Skip to content

Commit 2a42039

Browse files
eraydbighappyface
authored andcommitted
Backports for 5.2.2 (#431)
* Remove PHPDocumentor & change travis platform for hhvm tests (#429) * Remove dev-time dependency on phpdocumentor due to resolution headaches * Switch distro for hhvm testing to trusty (precise now unsupported) * Bugfix for #424 - add '?' for query string (#425) Note that this bugfix will cause empty query strings to be dropped (e.g. http://example.com?#blue becomes http://example.com#blue). This is because the '?' character is deliberately not captured as part of the query string, and the testsuite expects to be able to pass an empty query string and *not* have the '?' added for that case.
1 parent 429be23 commit 2a42039

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ matrix:
1818
- php: 7.1
1919
- php: 'nightly'
2020
- php: hhvm
21+
dist: trusty
2122
allow_failures:
2223
- php: 'nightly'
2324

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@
4040
},
4141
"require-dev": {
4242
"json-schema/JSON-Schema-Test-Suite": "1.2.0",
43-
"phpunit/phpunit": "^4.8.22",
4443
"friendsofphp/php-cs-fixer": "^2.1",
45-
"phpdocumentor/phpdocumentor": "^2.7"
44+
"phpunit/phpunit": "^4.8.22"
4645
},
4746
"autoload": {
4847
"psr-4": { "JsonSchema\\": "src/JsonSchema/" }

src/JsonSchema/Uri/UriResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public function generate(array $components)
6161
. $components['authority']
6262
. $components['path'];
6363

64-
if (array_key_exists('query', $components)) {
65-
$uri .= $components['query'];
64+
if (array_key_exists('query', $components) && strlen($components['query'])) {
65+
$uri .= '?' . $components['query'];
6666
}
6767
if (array_key_exists('fragment', $components)) {
6868
$uri .= '#' . $components['fragment'];

tests/Uri/UriResolverTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,22 @@ public function testResolveEmpty()
172172
)
173173
);
174174
}
175+
176+
public function testReversable()
177+
{
178+
$uri = 'scheme://user:password@authority/path?query#fragment';
179+
$split = $this->resolver->parse($uri);
180+
181+
// check that the URI was split as expected
182+
$this->assertEquals(array(
183+
'scheme' => 'scheme',
184+
'authority' => 'user:password@authority',
185+
'path' => '/path',
186+
'query' => 'query',
187+
'fragment' => 'fragment'
188+
), $split);
189+
190+
// check that the recombined URI matches the original input
191+
$this->assertEquals($uri, $this->resolver->generate($split));
192+
}
175193
}

0 commit comments

Comments
 (0)