Skip to content

Commit 6f542cf

Browse files
committed
Api: fixed URL parameters escaping
e.g. ' ' => '%20'
1 parent 23deddd commit 6f542cf

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

src/Github/Api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ protected function substituteUrlParameters(& $url, array & $parameters)
352352

353353
$parameter = $parameters[$m[2]];
354354
unset($parameters[$m[2]]);
355-
return $m[1] . $parameter;
355+
return $m[1] . rawurlencode($parameter);
356356
}, $url);
357357
}
358358

tests/Github/Api.substituteUrlParameters.phpt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class TestApi extends Milo\Github\Api
1616
}
1717

1818

19-
# substituteUrl()
19+
# URL parameters like :name
2020
test(function() {
2121
$api = new TestApi;
2222

@@ -50,3 +50,16 @@ test(function() {
5050
$api->substituteUrlParameters($url, $params);
5151
}, 'Milo\Github\MissingParameterException', "Missing parameter 'a:b' for URL path ':a:b'.");
5252
});
53+
54+
55+
# URL parameters like :name with special chars as value
56+
test(function() {
57+
$api = new TestApi;
58+
59+
$url = '/:name';
60+
$params = ['name' => 'with space'];
61+
$api->substituteUrlParameters($url, $params);
62+
63+
Assert::same('/with%20space', $url);
64+
Assert::same([], $params);
65+
});

0 commit comments

Comments
 (0)