From 15a3f2de2d531c777dc7a01cf9779d2e426e213c Mon Sep 17 00:00:00 2001 From: webchick Date: Thu, 11 Jun 2015 14:31:07 -0700 Subject: [PATCH] Issue #2501655 by tim.plunkett, hchonov, willzyx: ConfirmFormHelper::buildCancelLink() incorrectly handles ?destination URLs with a leading slash --- core/lib/Drupal/Core/Form/ConfirmFormHelper.php | 2 +- .../Tests/Core/Form/ConfirmFormHelperTest.php | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) 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; + } + }