Loading core/lib/Drupal/Core/Path/PathValidator.php +1 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ public function getUrlIfValid($path) { return Url::createFromPath($path); } $path = ltrim($path, '/'); $request = Request::create('/' . $path); $attributes = $this->getPathAttributes($path, $request); Loading core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php +10 −3 Original line number Diff line number Diff line Loading @@ -246,16 +246,16 @@ public function testIsValidWithNotExistingPath() { * Tests the getUrlIfValid() method when there is access. */ public function testGetUrlIfValidWithAccess() { $this->account->expects($this->once()) $this->account->expects($this->exactly(2)) ->method('hasPermission') ->with('link to any page') ->willReturn(FALSE); $this->accessAwareRouter->expects($this->once()) $this->accessAwareRouter->expects($this->exactly(2)) ->method('match') ->with('/test-path') ->willReturn([RouteObjectInterface::ROUTE_NAME => 'test_route', '_raw_variables' => new ParameterBag(['key' => 'value'])]); $this->pathProcessor->expects($this->once()) $this->pathProcessor->expects($this->exactly(2)) ->method('processInbound') ->willReturnArgument(0); Loading @@ -264,6 +264,13 @@ public function testGetUrlIfValidWithAccess() { $this->assertEquals('test_route', $url->getRouteName()); $this->assertEquals(['key' => 'value'], $url->getRouteParameters()); // Test with leading /. $url = $this->pathValidator->getUrlIfValid('/test-path'); $this->assertInstanceOf('Drupal\Core\Url', $url); $this->assertEquals('test_route', $url->getRouteName()); $this->assertEquals(['key' => 'value'], $url->getRouteParameters()); } /** Loading Loading
core/lib/Drupal/Core/Path/PathValidator.php +1 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ public function getUrlIfValid($path) { return Url::createFromPath($path); } $path = ltrim($path, '/'); $request = Request::create('/' . $path); $attributes = $this->getPathAttributes($path, $request); Loading
core/tests/Drupal/Tests/Core/Path/PathValidatorTest.php +10 −3 Original line number Diff line number Diff line Loading @@ -246,16 +246,16 @@ public function testIsValidWithNotExistingPath() { * Tests the getUrlIfValid() method when there is access. */ public function testGetUrlIfValidWithAccess() { $this->account->expects($this->once()) $this->account->expects($this->exactly(2)) ->method('hasPermission') ->with('link to any page') ->willReturn(FALSE); $this->accessAwareRouter->expects($this->once()) $this->accessAwareRouter->expects($this->exactly(2)) ->method('match') ->with('/test-path') ->willReturn([RouteObjectInterface::ROUTE_NAME => 'test_route', '_raw_variables' => new ParameterBag(['key' => 'value'])]); $this->pathProcessor->expects($this->once()) $this->pathProcessor->expects($this->exactly(2)) ->method('processInbound') ->willReturnArgument(0); Loading @@ -264,6 +264,13 @@ public function testGetUrlIfValidWithAccess() { $this->assertEquals('test_route', $url->getRouteName()); $this->assertEquals(['key' => 'value'], $url->getRouteParameters()); // Test with leading /. $url = $this->pathValidator->getUrlIfValid('/test-path'); $this->assertInstanceOf('Drupal\Core\Url', $url); $this->assertEquals('test_route', $url->getRouteName()); $this->assertEquals(['key' => 'value'], $url->getRouteParameters()); } /** Loading