Skip to content

Commit

Permalink
Ensure that relativeTo works when base path is empty and relative pat…
Browse files Browse the repository at this point in the history
…h has a query string

Merge branch 'master' of https://github.com/erisco/IRI
This closes #5
  • Loading branch information
lanthaler committed Dec 30, 2015
2 parents f89457a + 590a591 commit 6126ed8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions IRI.php
Expand Up @@ -395,9 +395,10 @@ public function relativeTo($base, $schemaRelative = false)
}

if (($baseSegments[$pos] !== $relativeSegments[$pos]) ||
((null === $relative->query) && (null === $relative->fragment))) {
// if the two paths differ or if there's neither a query component nor a fragment,
// we need to consider this IRI's path
((null === $relative->query) && (null === $relative->fragment)) ||
$base->path === '') {
// if the two paths differ or if there's neither a query component nor a fragment
// or there is no base path, we need to consider this IRI's path

if (($relative->path === '') && (false !== strpos($relativeSegments[$pos], ':'))) {
// if the first path segment contains a colon, we need to
Expand Down
1 change: 1 addition & 0 deletions Test/IriTest.php
Expand Up @@ -944,6 +944,7 @@ public function testRelativize($iri, $base, $schemaRelative, $expected)
public function relativizeProvider()
{
return array( // $iri, $base, $schemaRelative, $expected
array('http://example.com/x/y?k=v', 'http://example.com', false, '/x/y?k=v'),
array('http://ex/x/y/z', 'http://ex/x/y/z', false, 'z'),
array('https://example.com/x/y/z', 'http://example.com/x/y/z', false, 'https://example.com/x/y/z'),
array('http://example.com/x/y/z/', 'http://example.com/x/y/z/', false, './'),
Expand Down

0 comments on commit 6126ed8

Please sign in to comment.