diff --git a/core/lib/Drupal/Component/Utility/Url.php b/core/lib/Drupal/Component/Utility/Url.php index 07d959e..88eb752 100644 --- a/core/lib/Drupal/Component/Utility/Url.php +++ b/core/lib/Drupal/Component/Utility/Url.php @@ -228,7 +228,7 @@ public static function externalIsLocal($url, $base_url) { $base_host = parse_url($base_url, PHP_URL_HOST); $base_url = substr($base_url, strpos($base_url, $base_host) + strlen($base_host)); - if (!isset($url_parts['path'])) { + if (!isset($url_parts['path']) || $url_parts['path'] == '/') { return ($url_parts['host'] == $base_host); } else { diff --git a/core/tests/Drupal/Tests/Component/Utility/UrlTest.php b/core/tests/Drupal/Tests/Component/Utility/UrlTest.php index b4e0e3e..31d767e 100644 --- a/core/tests/Drupal/Tests/Component/Utility/UrlTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UrlTest.php @@ -409,13 +409,28 @@ protected function dataEnhanceWithPrefix(array $urls) { } /** + * Data provider for testExternalIsLocal() + */ + public function providerTestExternalIsLocal() { + return array ( + array('http://example.com/url', 'http://example.com/', TRUE), + array('http://example.com/url', 'http://moexample.com/', FALSE), + array('http://example.com/', 'http://example.com/', TRUE), + array('http://example.com', 'http://example.com/', TRUE), + array('http://example.com/', 'http://example.com', TRUE), + array('http://example.com', 'http://example.com', TRUE), + ); + } + + /** * Test externalIsLocal method. * + * @dataProvider providerTestExternalIsLocal + * * @see \Drupal\Component\Utility\Url::externalIsLocal() */ - public function testExternalIsLocal() { - $this->assertTrue(Url::externalIsLocal('http://example.com/url', 'http://example.com/')); - $this->assertFalse(Url::externalIsLocal('http://example.com/url', 'http://moexample.com/')); + public function testExternalIsLocal($url, $base_url, $expected) { + $this->assertEquals(Url::externalIsLocal($url, $base_url), $expected); } }