diff --git a/core/lib/Drupal/Core/Form/ConfirmFormHelper.php b/core/lib/Drupal/Core/Form/ConfirmFormHelper.php index 0902613f92b..e9c68fc0efb 100644 --- a/core/lib/Drupal/Core/Form/ConfirmFormHelper.php +++ b/core/lib/Drupal/Core/Form/ConfirmFormHelper.php @@ -34,7 +34,7 @@ class ConfirmFormHelper { if ($query->has('destination')) { $options = UrlHelper::parse($query->get('destination')); // @todo Revisit this in https://www.drupal.org/node/2418219. - $url = Url::fromUserInput('/' . $options['path'], $options); + $url = Url::fromUserInput('/' . ltrim($options['path'], '/'), $options); } // Check for a route-based cancel link. else { diff --git a/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php b/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php index a96ac58cf08..1dc65a954c3 100644 --- a/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php +++ b/core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php @@ -92,9 +92,11 @@ class ConfirmFormHelperTest extends UnitTestCase { * @covers ::buildCancelLink * * Tests a cancel link provided by the destination. + * + * @dataProvider providerTestCancelLinkDestination */ - public function testCancelLinkDestination() { - $query = array('destination' => 'baz'); + public function testCancelLinkDestination($destination) { + $query = array('destination' => $destination); $form = $this->getMock('Drupal\Core\Form\ConfirmFormInterface'); $path_validator = $this->getMock('Drupal\Core\Path\PathValidatorInterface'); @@ -112,4 +114,14 @@ class ConfirmFormHelperTest extends UnitTestCase { $this->assertSame($url, $link['#url']); } + /** + * Provides test data for testCancelLinkDestination(). + */ + public function providerTestCancelLinkDestination() { + $data = []; + $data[] = ['baz']; + $data[] = ['/baz']; + return $data; + } + }