Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/JsonSchema/Uri/UriResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public function generate(array $components)
. $components['authority']
. $components['path'];

if (array_key_exists('query', $components)) {
$uri .= $components['query'];
if (array_key_exists('query', $components) && strlen($components['query'])) {
$uri .= '?' . $components['query'];
}
if (array_key_exists('fragment', $components)) {
$uri .= '#' . $components['fragment'];
Expand Down
18 changes: 18 additions & 0 deletions tests/Uri/UriResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,22 @@ public function testResolveEmpty()
)
);
}

public function testReversable()
{
$uri = 'scheme://user:password@authority/path?query#fragment';
$split = $this->resolver->parse($uri);

// check that the URI was split as expected
$this->assertEquals(array(
'scheme' => 'scheme',
'authority' => 'user:password@authority',
'path' => '/path',
'query' => 'query',
'fragment' => 'fragment'
), $split);

// check that the recombined URI matches the original input
$this->assertEquals($uri, $this->resolver->generate($split));
}
}