Issue #2501655 by tim.plunkett, hchonov, willzyx: ConfirmFormHelper::buildCancelLink() incorrectly handles ?destination URLs with a leading slash
parent
0afbdd4c2d
commit
15a3f2de2d
|
@ -34,7 +34,7 @@ class ConfirmFormHelper {
|
||||||
if ($query->has('destination')) {
|
if ($query->has('destination')) {
|
||||||
$options = UrlHelper::parse($query->get('destination'));
|
$options = UrlHelper::parse($query->get('destination'));
|
||||||
// @todo Revisit this in https://www.drupal.org/node/2418219.
|
// @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.
|
// Check for a route-based cancel link.
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -92,9 +92,11 @@ class ConfirmFormHelperTest extends UnitTestCase {
|
||||||
* @covers ::buildCancelLink
|
* @covers ::buildCancelLink
|
||||||
*
|
*
|
||||||
* Tests a cancel link provided by the destination.
|
* Tests a cancel link provided by the destination.
|
||||||
|
*
|
||||||
|
* @dataProvider providerTestCancelLinkDestination
|
||||||
*/
|
*/
|
||||||
public function testCancelLinkDestination() {
|
public function testCancelLinkDestination($destination) {
|
||||||
$query = array('destination' => 'baz');
|
$query = array('destination' => $destination);
|
||||||
$form = $this->getMock('Drupal\Core\Form\ConfirmFormInterface');
|
$form = $this->getMock('Drupal\Core\Form\ConfirmFormInterface');
|
||||||
|
|
||||||
$path_validator = $this->getMock('Drupal\Core\Path\PathValidatorInterface');
|
$path_validator = $this->getMock('Drupal\Core\Path\PathValidatorInterface');
|
||||||
|
@ -112,4 +114,14 @@ class ConfirmFormHelperTest extends UnitTestCase {
|
||||||
$this->assertSame($url, $link['#url']);
|
$this->assertSame($url, $link['#url']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides test data for testCancelLinkDestination().
|
||||||
|
*/
|
||||||
|
public function providerTestCancelLinkDestination() {
|
||||||
|
$data = [];
|
||||||
|
$data[] = ['baz'];
|
||||||
|
$data[] = ['/baz'];
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue