diff --git a/core/lib/Drupal/Component/Utility/Url.php b/core/lib/Drupal/Component/Utility/Url.php index cdc01c8..07d959e 100644 --- a/core/lib/Drupal/Component/Utility/Url.php +++ b/core/lib/Drupal/Component/Utility/Url.php @@ -226,6 +226,7 @@ public static function isExternal($path) { public static function externalIsLocal($url, $base_url) { $url_parts = parse_url($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'])) { return ($url_parts['host'] == $base_host); diff --git a/core/tests/Drupal/Tests/Component/Utility/UrlTest.php b/core/tests/Drupal/Tests/Component/Utility/UrlTest.php index de62324..b4e0e3e 100644 --- a/core/tests/Drupal/Tests/Component/Utility/UrlTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/UrlTest.php @@ -408,4 +408,14 @@ protected function dataEnhanceWithPrefix(array $urls) { return $data; } + /** + * Test externalIsLocal method. + * + * @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/')); + } + }