Skip to content

Commit 849137a

Browse files
committed
Use explicit argument separator when building url
1 parent 5fd3b4b commit 849137a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/Curl/Curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ private function __get_totalTime() {
10941094
*/
10951095
private function buildURL($url, $data = array())
10961096
{
1097-
return $url . (empty($data) ? '' : '?' . http_build_query($data));
1097+
return $url . (empty($data) ? '' : '?' . http_build_query($data, '', '&'));
10981098
}
10991099

11001100
/**

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,4 +2807,29 @@ public function testOptionSet()
28072807

28082808
$this->assertFalse(isset($options[CURLOPT_COOKIE]));
28092809
}
2810+
2811+
public function testBuildUrlArgSeparator()
2812+
{
2813+
$base_url = 'https://www.example.com/path';
2814+
$data = array(
2815+
'arg' => 'value',
2816+
'another' => 'one',
2817+
);
2818+
$expected_url = $base_url . '?arg=value&another=one';
2819+
2820+
foreach (array(false, '&', '&') as $arg_separator) {
2821+
if ($arg_separator) {
2822+
ini_set('arg_separator.output', $arg_separator);
2823+
}
2824+
2825+
$curl = new Curl();
2826+
2827+
$reflector = new ReflectionObject($curl);
2828+
$method = $reflector->getMethod('buildURL');
2829+
$method->setAccessible(true);
2830+
2831+
$actual_url = $method->invoke($curl, $base_url, $data);
2832+
$this->assertEquals($expected_url, $actual_url);
2833+
}
2834+
}
28102835
}

0 commit comments

Comments
 (0)