From 85e94ba1b1786eaa8cf60a969be0ea740ca05d58 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Thu, 28 Jul 2022 23:47:29 -0400 Subject: [PATCH] Fix #725: Encode keys for post data with numeric keys --- src/Curl/Curl.php | 2 +- tests/PHPCurlClass/PHPCurlClassTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 7beae7a..e29592f 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -207,7 +207,7 @@ class Curl // php_raw_url_encode() // php_url_encode() // https://github.com/php/php-src/blob/master/ext/standard/http.c - return urlencode($k) . '=' . urlencode(strval($v)); + return urlencode(strval($k)) . '=' . urlencode(strval($v)); }, array_keys($data), array_values($data))); } diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index fed7c61..c44cda8 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -72,6 +72,15 @@ class CurlTest extends \PHPUnit\Framework\TestCase } } + public function testBuildPostDataIntegerKey() + { + $curl = new Curl(); + $this->assertEquals('abc=foo&123=bar', $curl->buildPostData([ + 'abc' => 'foo', + '123' => 'bar', + ])); + } + public function testUserAgent() { $php_version = preg_replace('/([\.\+\?\*\(\)\[\]\^\$\/])/', '\\\\\1', 'PHP/' . PHP_VERSION);