Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Http/Headers/src/HeaderUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public static bool TryParseSeconds(StringValues headerValues, string targetValue

for (var i = 0; i < headerValues.Count; i++)
{
var segment = headerValues[i]!;
var segment = headerValues[i] ?? string.Empty;

// Trim leading white space
var current = HttpRuleParser.GetWhitespaceLength(segment, 0);
Expand Down Expand Up @@ -297,7 +297,7 @@ public static bool ContainsCacheDirective(StringValues cacheControlDirectives, s

for (var i = 0; i < cacheControlDirectives.Count; i++)
{
var segment = cacheControlDirectives[i]!;
var segment = cacheControlDirectives[i] ?? string.Empty;

// Trim leading white space
var current = HttpRuleParser.GetWhitespaceLength(segment, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Http/src/Internal/ResponseCookies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void Delete(string key, CookieOptions options)

for (var i = 0; i < values.Length; i++)
{
var value = values[i]!;
var value = values[i] ?? string.Empty;
if (!rejectPredicate(value, encodedKeyPlusEquals, options))
{
newValues.Add(value);
Expand Down
2 changes: 1 addition & 1 deletion src/Http/WebUtilities/src/KeyValueAccumulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void Append(string key, string value)
StringValues values;
if (_accumulator.TryGetValue(key, out values))
{
if (StringValues.IsNullOrEmpty(values))
if (values.Count == 0)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual bug.

{
// Marker entry for this key to indicate entry already in expanding list dictionary
_expandingAccumulator[key].Add(value);
Expand Down
15 changes: 10 additions & 5 deletions src/Http/WebUtilities/test/FormPipeReaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipelines;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Primitives;
using Xunit;

namespace Microsoft.AspNetCore.WebUtilities
{
Expand Down Expand Up @@ -567,6 +562,16 @@ public void ParseFormWithIncompleteValueWhenIsFinalBlockSucceeds(ReadOnlySequenc
Assert.Equal("", values["b"]);
}

[Fact]
public async Task ReadFormAsync_AccumulatesEmptyKeys()
{
var bodyPipe = await MakePipeReader("&&&");

var formCollection = await ReadFormAsync(new FormPipeReader(bodyPipe));

Assert.Single(formCollection);
}

public static TheoryData<ReadOnlySequence<byte>> IncompleteFormKeys =>
new TheoryData<ReadOnlySequence<byte>>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public string CreateStorageVaryByKey(ResponseCachingContext context)
var requestHeaders = context.HttpContext.Request.Headers;
for (var i = 0; i < headersCount; i++)
{
var header = varyByRules!.Headers[i]!;
var header = varyByRules!.Headers[i] ?? string.Empty;
var headerValues = requestHeaders[header];
builder.Append(KeyDelimiter)
.Append(header)
Expand Down Expand Up @@ -174,7 +174,7 @@ public string CreateStorageVaryByKey(ResponseCachingContext context)
{
for (var i = 0; i < varyByRules.QueryKeys.Count; i++)
{
var queryKey = varyByRules.QueryKeys[i]!;
var queryKey = varyByRules.QueryKeys[i] ?? string.Empty;
var queryKeyValues = context.HttpContext.Request.Query[queryKey];
builder.Append(KeyDelimiter)
.Append(queryKey)
Expand Down
7 changes: 5 additions & 2 deletions src/Servers/IIS/IIS/src/Core/IISHttpContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,16 @@ public unsafe void SetResponseHeaders()
var knownHeaderIndex = HttpApiTypes.HTTP_RESPONSE_HEADER_ID.IndexOfKnownHeader(headerPair.Key);
for (var i = 0; i < headerValues.Count; i++)
{
if (string.IsNullOrEmpty(headerValues[i]))
var headerValue = headerValues[i];

if (string.IsNullOrEmpty(headerValue))
{
continue;
}

var isFirst = i == 0;
var headerValueBytes = Encoding.UTF8.GetBytes(headerValues[i]!);
var headerValueBytes = Encoding.UTF8.GetBytes(headerValue);

fixed (byte* pHeaderValue = headerValueBytes)
{
if (knownHeaderIndex == -1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public static void ValidateHeaderValueCharacters(string headerName, StringValues
var count = headerValues.Count;
for (var i = 0; i < count; i++)
{
ValidateHeaderValueCharacters(headerValues[i]!, requireAscii);
ValidateHeaderValueCharacters(headerValues[i] ?? string.Empty, requireAscii);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Shared/RangeHelper/RangeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static (bool isRangeRequest, RangeItemHeaderValue? range) ParseRange(
}

// Perf: Check for a single entry before parsing it
if (rawRangeHeader.Count > 1 || rawRangeHeader[0]!.IndexOf(',') >= 0)
if (rawRangeHeader.Count > 1 || (rawRangeHeader[0] ?? string.Empty).IndexOf(',') >= 0)
{
logger.LogDebug("Multiple ranges are not supported.");

Expand Down