Skip to content

Commit cd08b5d

Browse files
author
Dane Westvik
committed
Support for urls with query parameters
1 parent 3f4e0fc commit cd08b5d

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/Curl/Curl.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,10 +1193,11 @@ private function buildUrl($url, $mixed_data = '')
11931193
{
11941194
$query_string = '';
11951195
if (!empty($mixed_data)) {
1196+
$query_mark = (strpos($url,'?')>0)? '&':'?';
11961197
if (is_string($mixed_data)) {
1197-
$query_string .= '?' . $mixed_data;
1198+
$query_string .= $query_mark . $mixed_data;
11981199
} elseif (is_array($mixed_data)) {
1199-
$query_string .= '?' . http_build_query($mixed_data, '', '&');
1200+
$query_string .= $query_mark . http_build_query($mixed_data, '', '&');
12001201
}
12011202
}
12021203
return $url . $query_string;

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3106,6 +3106,23 @@ public function testBuildUrlArgs()
31063106
),
31073107
'expected' => 'https://www.example.com/?a=1&b=2&c=3',
31083108
),
3109+
array(
3110+
'args' => array(
3111+
'url' => 'https://www.example.com/?a=base',
3112+
'mixed_data' => array(
3113+
'b' => '2',
3114+
'c' => '3',
3115+
),
3116+
),
3117+
'expected' => 'https://www.example.com/?a=base&b=2&c=3',
3118+
),
3119+
array(
3120+
'args' => array(
3121+
'url' => 'https://www.example.com/?a=base',
3122+
'mixed_data' => 'b=2&c=3'
3123+
),
3124+
'expected' => 'https://www.example.com/?a=base&b=2&c=3',
3125+
),
31093126
array(
31103127
'args' => array(
31113128
'url' => 'https://www.example.com/',

0 commit comments

Comments
 (0)