Przeglądaj źródła

Added null validation in RedirectHandler (#28276)

Summary of the changes 
 - Added null check to response.headers.location to prevent NullReferenceException in RedirectHandler class

Addresses #27035
jose 5 lat temu
rodzic
commit
fc70b25e7a

+ 9 - 5
src/Mvc/Mvc.Testing/src/Handlers/RedirectHandler.cs

@@ -134,14 +134,18 @@ namespace Microsoft.AspNetCore.Mvc.Testing.Handlers
             HttpContent originalContent)
         {
             var location = response.Headers.Location;
-            if (!location.IsAbsoluteUri)
+            if (location != null)
             {
-                location = new Uri(
-                    new Uri(response.RequestMessage.RequestUri.GetLeftPart(UriPartial.Authority)),
-                    location);
+                if (!location.IsAbsoluteUri)
+                {
+                    location = new Uri(
+                        new Uri(response.RequestMessage.RequestUri.GetLeftPart(UriPartial.Authority)),
+                        location);
+                }
+
+                redirect.RequestUri = location;
             }
 
-            redirect.RequestUri = location;
             if (!ShouldKeepVerb(response))
             {
                 redirect.Method = HttpMethod.Get;