diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index 123cc7a..5fc1c31 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -196,11 +196,19 @@ public static function routed($route_name, $route_parameters = array(), $options * @return \Drupal\Core\Url * A new Url object for an unrouted (non-Drupal) URL. * + * @throws \InvalidArgumentException + * Thrown when the passed in path has no schema. + * * @see static::routed() */ public static function unrouted($uri, $options = array()) { + if (!parse_url($uri, PHP_URL_SCHEME)) { + throw new \InvalidArgumentException('You must use a valid URI scheme. Use base:// for a path e.g. to a Drupal file that needs the base path.'); + } + $url = new static($uri, array(), $options); $url->setUnrouted(); + return $url; } diff --git a/core/lib/Drupal/Core/Utility/UnroutedUrlAssemblerInterface.php b/core/lib/Drupal/Core/Utility/UnroutedUrlAssemblerInterface.php index 36fca11..f72d876 100644 --- a/core/lib/Drupal/Core/Utility/UnroutedUrlAssemblerInterface.php +++ b/core/lib/Drupal/Core/Utility/UnroutedUrlAssemblerInterface.php @@ -49,6 +49,9 @@ * * @return * A string containing a relative or absolute URL. + * + * @throws \InvalidArgumentException + * Thrown when the passed in path has no schema. */ public function assemble($uri, array $options = array()); diff --git a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php index 472dc64..317ad62 100644 --- a/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php +++ b/core/tests/Drupal/Tests/Core/UnroutedUrlTest.php @@ -104,6 +104,17 @@ public function testCreateFromRequest() { } /** + * Tests the unrouted method with an non-scheme path. + * + * @covers ::unrouted() + * + * @expectedException \InvalidArgumentException + */ + public function testUnroutedWithNonScheme() { + Url::unrouted('test'); + } + + /** * Tests the isExternal() method. * * @depends testCreateFromPath