diff --git a/core/lib/Drupal/Core/Path/CurrentPathStack.php b/core/lib/Drupal/Core/Path/CurrentPathStack.php index 51b97cd71e..4a04173c67 100644 --- a/core/lib/Drupal/Core/Path/CurrentPathStack.php +++ b/core/lib/Drupal/Core/Path/CurrentPathStack.php @@ -46,7 +46,7 @@ public function __construct(RequestStack $request_stack) { * (optional) The request. * * @return string - * Returns the path, without leading slashes. + * Returns the encoded path with a leading slash. */ public function getPath(Request $request = NULL) { if (!isset($request)) { @@ -63,13 +63,20 @@ public function getPath(Request $request = NULL) { * Sets the current path. * * @param string $path - * The path. + * The path, with a leading slash. * @param \Symfony\Component\HttpFoundation\Request $request * (optional) The request. * + * @throws \LogicException + * Thrown when $path does not contain a leading slash. + * * @return $this */ public function setPath($path, Request $request = NULL) { + if (strpos($path, '/') !== 0) { + throw new \LogicException(sprintf('The path %s must begin with a leading slash.', $path)); + } + if (!isset($request)) { $request = $this->requestStack->getCurrentRequest(); }