diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index 4fc013f..618bc98 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -735,7 +735,14 @@ protected function buildFormAction() { // @todo Remove this parsing once these are removed from the request in // https://www.drupal.org/node/2504709. $parsed = UrlHelper::parse($request_uri); - unset($parsed['query'][static::AJAX_FORM_REQUEST], $parsed['query'][MainContentViewSubscriber::WRAPPER_FORMAT], $parsed['query']['destination']); + unset($parsed['query'][static::AJAX_FORM_REQUEST], $parsed['query'][MainContentViewSubscriber::WRAPPER_FORMAT]); + + // Ignore the destination if the form is rendered inside a subrequest on a + // 403/404 page. + if ($request->query->has('_exception_statuscode') && $request->query->has('destination')) { + unset($parsed['query']['destination']); + } + return $parsed['path'] . ($parsed['query'] ? ('?' . UrlHelper::buildQuery($parsed['query'])) : ''); }