Issue #2501655 by tim.plunkett, hchonov, willzyx: ConfirmFormHelper::buildCancelLink() incorrectly handles ?destination URLs with a leading slash

8.0.x
webchick 2015-06-11 14:31:07 -07:00
parent 0afbdd4c2d
commit 15a3f2de2d
2 changed files with 15 additions and 3 deletions

View File

@ -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 {

View File

@ -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;
}
}