From cd08b5dee7d2a9ae04acc19e2237d8cd193dccc7 Mon Sep 17 00:00:00 2001 From: Dane Westvik Date: Thu, 24 Aug 2017 13:36:23 -0700 Subject: [PATCH] Support for urls with query parameters --- src/Curl/Curl.php | 5 +++-- tests/PHPCurlClass/PHPCurlClassTest.php | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index 5eba1fb..d8a50ad 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -1193,10 +1193,11 @@ class Curl { $query_string = ''; if (!empty($mixed_data)) { + $query_mark = (strpos($url,'?')>0)? '&':'?'; if (is_string($mixed_data)) { - $query_string .= '?' . $mixed_data; + $query_string .= $query_mark . $mixed_data; } elseif (is_array($mixed_data)) { - $query_string .= '?' . http_build_query($mixed_data, '', '&'); + $query_string .= $query_mark . http_build_query($mixed_data, '', '&'); } } return $url . $query_string; diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index ccc86c0..33b2dd1 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -3106,6 +3106,23 @@ class CurlTest extends \PHPUnit\Framework\TestCase ), 'expected' => 'https://www.example.com/?a=1&b=2&c=3', ), + array( + 'args' => array( + 'url' => 'https://www.example.com/?a=base', + 'mixed_data' => array( + 'b' => '2', + 'c' => '3', + ), + ), + 'expected' => 'https://www.example.com/?a=base&b=2&c=3', + ), + array( + 'args' => array( + 'url' => 'https://www.example.com/?a=base', + 'mixed_data' => 'b=2&c=3' + ), + 'expected' => 'https://www.example.com/?a=base&b=2&c=3', + ), array( 'args' => array( 'url' => 'https://www.example.com/',