Skip to content

Commit 484d87f

Browse files
authored
Merge pull request php-curl-class#373 from zachborboa/master
Use explicit argument separator when building url
2 parents 783594a + 849137a commit 484d87f

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ $multi_curl->addGet('https://www.bing.com/search', array(
173173
$multi_curl->start(); // Blocks until all items in the queue have been processed.
174174
```
175175

176+
More examples are available under [/examples](https://github.com/php-curl-class/php-curl-class/tree/master/examples).
177+
176178
### Available Methods
177179
```php
178180
Curl::__construct($base_url = null)

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)