From c6fe27f63e078abc8b6aa68f15ad30ef3ae14375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Simon?= Date: Mon, 25 Feb 2013 15:57:52 +0100 Subject: [PATCH] [2.3] [DomCrawler] adds schema relative URL support to link --- src/Symfony/Component/DomCrawler/Link.php | 5 +++++ src/Symfony/Component/DomCrawler/Tests/LinkTest.php | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/Symfony/Component/DomCrawler/Link.php b/src/Symfony/Component/DomCrawler/Link.php index 34bbf11fb0..7d0ce679be 100644 --- a/src/Symfony/Component/DomCrawler/Link.php +++ b/src/Symfony/Component/DomCrawler/Link.php @@ -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; diff --git a/src/Symfony/Component/DomCrawler/Tests/LinkTest.php b/src/Symfony/Component/DomCrawler/Tests/LinkTest.php index 5d40179a53..003dd238ed 100644 --- a/src/Symfony/Component/DomCrawler/Tests/LinkTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/LinkTest.php @@ -94,6 +94,10 @@ class LinkTest extends \PHPUnit_Framework_TestCase 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'),