From f220f6e2eb641feca0b61c2af6808fb29a842cf6 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 21 Mar 2018 20:32:02 +0000 Subject: [PATCH 1/2] React to StringValues --- .../Extensions/HeaderDictionaryExtensions.cs | 2 +- .../HeaderDictionary.cs | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/HeaderDictionaryExtensions.cs b/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/HeaderDictionaryExtensions.cs index 5cc06484..0e31660d 100644 --- a/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/HeaderDictionaryExtensions.cs +++ b/src/Microsoft.AspNetCore.Http.Abstractions/Extensions/HeaderDictionaryExtensions.cs @@ -39,7 +39,7 @@ public static void AppendCommaSeparatedValues(this IHeaderDictionary headers, st /// the associated values from the collection separated into individual values, or StringValues.Empty if the key is not present. public static string[] GetCommaSeparatedValues(this IHeaderDictionary headers, string key) { - return ParsingHelpers.GetHeaderSplit(headers, key).ToArray(); + return ParsingHelpers.GetHeaderSplit(headers, key); } /// diff --git a/src/Microsoft.AspNetCore.Http/HeaderDictionary.cs b/src/Microsoft.AspNetCore.Http/HeaderDictionary.cs index bc0b7a26..ed3b3ba6 100644 --- a/src/Microsoft.AspNetCore.Http/HeaderDictionary.cs +++ b/src/Microsoft.AspNetCore.Http/HeaderDictionary.cs @@ -74,7 +74,7 @@ public StringValues this[string key] } ThrowIfReadOnly(); - if (StringValues.IsNullOrEmpty(value)) + if (value.ToString().Length == 0) { Store?.Remove(key); } @@ -177,8 +177,11 @@ public void Add(KeyValuePair item) throw new ArgumentNullException("The key is null"); } ThrowIfReadOnly(); - EnsureStore(1); - Store.Add(item.Key, item.Value); + if (item.Value.ToString().Length > 0) + { + EnsureStore(1); + Store.Add(item.Key, item.Value); + } } /// @@ -193,8 +196,11 @@ public void Add(string key, StringValues value) throw new ArgumentNullException(nameof(key)); } ThrowIfReadOnly(); - EnsureStore(1); - Store.Add(key, value); + if (value.ToString().Length > 0) + { + EnsureStore(1); + Store.Add(key, value); + } } /// From 5a9b62f82668bc92e53f099285cfc9863cefc503 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Sat, 24 Mar 2018 04:55:50 +0000 Subject: [PATCH 2/2] Use IsNull --- .../Internal/ParsingHelpers.cs | 2 +- src/Microsoft.AspNetCore.WebUtilities/KeyValueAccumulator.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Http.Abstractions/Internal/ParsingHelpers.cs b/src/Microsoft.AspNetCore.Http.Abstractions/Internal/ParsingHelpers.cs index 185fc40a..c3bcdefd 100644 --- a/src/Microsoft.AspNetCore.Http.Abstractions/Internal/ParsingHelpers.cs +++ b/src/Microsoft.AspNetCore.Http.Abstractions/Internal/ParsingHelpers.cs @@ -153,7 +153,7 @@ public static void AppendHeaderUnmodified(IHeaderDictionary headers, string key, throw new ArgumentNullException(nameof(key)); } - if (values.Count == 0) + if (values.IsNull) { return; } diff --git a/src/Microsoft.AspNetCore.WebUtilities/KeyValueAccumulator.cs b/src/Microsoft.AspNetCore.WebUtilities/KeyValueAccumulator.cs index 5ae402e5..49ec9f2a 100644 --- a/src/Microsoft.AspNetCore.WebUtilities/KeyValueAccumulator.cs +++ b/src/Microsoft.AspNetCore.WebUtilities/KeyValueAccumulator.cs @@ -22,7 +22,7 @@ public void Append(string key, string value) StringValues values; if (_accumulator.TryGetValue(key, out values)) { - if (values.Count == 0) + if (values.IsNull) { // Marker entry for this key to indicate entry already in expanding list dictionary _expandingAccumulator[key].Add(value);