Skip to content

Commit c017d2b

Browse files
committed
Bugfix for jsonrainbow#424 - add '?' for query string
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 2d404b8 commit c017d2b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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)