diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 64e01e6..5f9de04 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -731,6 +731,7 @@ protected function buildFormAction() { // https://www.drupal.org/node/2504709. $parsed = UrlHelper::parse($request_uri); unset($parsed['query'][static::AJAX_FORM_REQUEST], $parsed['query'][MainContentViewSubscriber::WRAPPER_FORMAT]); + $parsed['path'] = '/' . ltrim($parsed['path'], '/'); return $parsed['path'] . ($parsed['query'] ? ('?' . UrlHelper::buildQuery($parsed['query'])) : ''); } diff --git a/core/modules/system/src/Tests/Form/ExternalFormUrlTest.php b/core/modules/system/src/Tests/Form/ExternalFormUrlTest.php index a92e047..35d22f78 100644 --- a/core/modules/system/src/Tests/Form/ExternalFormUrlTest.php +++ b/core/modules/system/src/Tests/Form/ExternalFormUrlTest.php @@ -16,7 +16,7 @@ use Symfony\Component\HttpFoundation\Request; /** - * Ensures that form actions can't be tricked into sending to external urls. + * Ensures that form actions can't be tricked into sending to external URLs. * * @group system */ @@ -86,12 +86,9 @@ public function testExternalUrlBehavior() { $form = \Drupal::formBuilder()->getForm($this); $markup = \Drupal::service('renderer')->renderRoot($form); - $dom = new \DOMDocument(); - $dom->loadXML($markup); - - $xpath = new \DOMXPath($dom); - $form = $xpath->query('//form'); - $action = $form->item(0)->getAttribute('action'); + $this->setRawContent($markup); + $elements = $this->xpath('//form/@action'); + $action = (string) $elements[0]; $this->assertNotEqual('//example.org', $action); $this->assertEqual('/example.org', $action);