merged branch jfsimon/issue-7169 (PR #7179)

This PR was squashed before being merged into the master branch (closes #7179).

Commits
-------

c6fe27f [2.3] [DomCrawler] adds schema relative URL support to link

Discussion
----------

[2.3] [DomCrawler] adds schema relative URL support to link

Adds support for `//relative/schema` URLs to `DomCrawler` links.

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #7169

---------------------------------------------------------------------------

by stof at 2013-02-25T19:17:10Z

👍
This commit is contained in:
Fabien Potencier 2013-03-06 17:43:17 +01:00
commit d59cf10593
2 changed files with 9 additions and 0 deletions

View File

@ -120,6 +120,11 @@ class Link
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;

View File

@ -96,6 +96,10 @@ class LinkTest extends \PHPUnit_Framework_TestCase
array('https://login.foo.com/foo', 'https://localhost/bar/', 'https://login.foo.com/foo'),
array('mailto:foo@bar.com', 'http://localhost/foo', 'mailto:foo@bar.com'),
// 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'),