Skip to content

Commit 957f76f

Browse files
authored
Use IndexOf to find closing quote in WarningHeaderValue (#76804)
1 parent 0f015ec commit 957f76f

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/libraries/System.Net.Http/src/System/Net/Http/Headers/WarningHeaderValue.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -280,19 +280,12 @@ private static bool TryReadDate(string input, ref int current, out DateTimeOffse
280280

281281
// Find the closing '"'
282282
int dateStartIndex = current;
283-
while (current < input.Length)
283+
int quote = input.AsSpan(current).IndexOf('"');
284+
if (quote <= 0) // no quote was found or it was the first character (meaning an empty quoted string)
284285
{
285-
if (input[current] == '"')
286-
{
287-
break;
288-
}
289-
current++;
290-
}
291-
292-
if ((current == input.Length) || (current == dateStartIndex))
293-
{
294-
return false; // we couldn't find the closing '"' or we have an empty quoted string.
286+
return false;
295287
}
288+
current += quote;
296289

297290
DateTimeOffset temp;
298291
if (!HttpDateParser.TryParse(input.AsSpan(dateStartIndex, current - dateStartIndex), out temp))

0 commit comments

Comments
 (0)