Skip to content

Commit fc70b25

Browse files
authored
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
1 parent 7ce071b commit fc70b25

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Mvc/Mvc.Testing/src/Handlers/RedirectHandler.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,18 @@ private static void UpdateRedirectRequest(
134134
HttpContent originalContent)
135135
{
136136
var location = response.Headers.Location;
137-
if (!location.IsAbsoluteUri)
137+
if (location != null)
138138
{
139-
location = new Uri(
140-
new Uri(response.RequestMessage.RequestUri.GetLeftPart(UriPartial.Authority)),
141-
location);
139+
if (!location.IsAbsoluteUri)
140+
{
141+
location = new Uri(
142+
new Uri(response.RequestMessage.RequestUri.GetLeftPart(UriPartial.Authority)),
143+
location);
144+
}
145+
146+
redirect.RequestUri = location;
142147
}
143148

144-
redirect.RequestUri = location;
145149
if (!ShouldKeepVerb(response))
146150
{
147151
redirect.Method = HttpMethod.Get;

0 commit comments

Comments
 (0)