Skip to content

Commit

Permalink
[2.3] [DomCrawler] adds schema relative URL support to link
Browse files Browse the repository at this point in the history
  • Loading branch information
jfsimon authored and fabpot committed Mar 6, 2013
1 parent fb7004b commit c6fe27f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Symfony/Component/DomCrawler/Link.php
Expand Up @@ -120,6 +120,11 @@ public function getUri()
return $baseUri.$uri;
}

// absolute URL with relative schema
if (0 === strpos($uri, '//')) {
return preg_replace('#^([^/]*)//.*$#', '$1', $this->currentUri).$uri;
}

// absolute path
if ('/' === $uri[0]) {
return preg_replace('#^(.*?//[^/]+)(?:\/.*)?$#', '$1', $this->currentUri).$uri;
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/DomCrawler/Tests/LinkTest.php
Expand Up @@ -94,6 +94,10 @@ public function getGetUriTests()

array('http://login.foo.com/foo', 'http://localhost/bar/', 'http://login.foo.com/foo'),

// tests schema relative URL (issue #7169)
array('//login.foo.com/foo', 'http://localhost/bar/', 'http://login.foo.com/foo'),
array('//login.foo.com/foo', 'https://localhost/bar/', 'https://login.foo.com/foo'),

array('?foo=2', 'http://localhost?foo=1', 'http://localhost?foo=2'),
array('?foo=2', 'http://localhost/?foo=1', 'http://localhost/?foo=2'),
array('?foo=2', 'http://localhost/bar?foo=1', 'http://localhost/bar?foo=2'),
Expand Down

0 comments on commit c6fe27f

Please sign in to comment.