From c7774d2181dd341673cf29eaad91339bd4264e9d Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Sat, 25 Sep 2021 16:46:21 +0100
Subject: [PATCH] Issue #3238942 by andypost, alexpott:
 \Drupal\Core\Routing\RedirectDestination::get() causes deprecation errors on
 PHP 8.1

---
 core/lib/Drupal/Core/Routing/RedirectDestination.php | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/core/lib/Drupal/Core/Routing/RedirectDestination.php b/core/lib/Drupal/Core/Routing/RedirectDestination.php
index 1945e333c146..3aba3e4223c3 100644
--- a/core/lib/Drupal/Core/Routing/RedirectDestination.php
+++ b/core/lib/Drupal/Core/Routing/RedirectDestination.php
@@ -57,11 +57,12 @@ public function getAsArray() {
   public function get() {
     if (!isset($this->destination)) {
       $query = $this->requestStack->getCurrentRequest()->query;
-      if (UrlHelper::isExternal($query->get('destination'))) {
-        $this->destination = '/';
-      }
-      elseif ($query->has('destination')) {
+      if ($query->has('destination')) {
         $this->destination = $query->get('destination');
+        if (UrlHelper::isExternal($this->destination)) {
+          // See https://www.drupal.org/node/2454955 for external redirects.
+          $this->destination = '/';
+        }
       }
       else {
         $this->destination = $this->urlGenerator->generateFromRoute('<current>', [], ['query' => UrlHelper::filterQueryParameters($query->all())]);
-- 
GitLab