Skip to content

Commit 57a9b65

Browse files
committed
Addressing feedback given by asp.net team
1 parent 5f811cd commit 57a9b65

File tree

8 files changed

+17
-18
lines changed

8 files changed

+17
-18
lines changed

src/Antiforgery/test/DefaultAntiforgeryTokenStoreTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public void Append(string key, string value)
491491
throw new NotImplementedException();
492492
}
493493

494-
public void Append(IDictionary<string, string> keyValuePairs, CookieOptions options)
494+
public void Append(IEnumerable<KeyValuePair<string, string>> keyValuePairs, CookieOptions options)
495495
{
496496
throw new NotImplementedException();
497497
}

src/Http/Http.Features/src/IResponseCookies.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public interface IResponseCookies
3030
/// </summary>
3131
/// <param name="keyValuePairs">Key value pair collections whose elements will be added as cookies.</param>
3232
/// <param name="options"><see cref="CookieOptions"/> included in new cookie settings.</param>
33-
void Append(IDictionary<string, string> keyValuePairs, CookieOptions options);
33+
void Append(IEnumerable<KeyValuePair<string, string>> keyValuePairs, CookieOptions options);
3434

3535
/// <summary>
3636
/// Sets an expired cookie.

src/Http/Http.Features/src/PublicAPI.Unshipped.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ Microsoft.AspNetCore.Http.Features.IFeatureCollection.Set<TFeature>(TFeature? in
1515
Microsoft.AspNetCore.Http.Features.IServerVariablesFeature.this[string! variableName].get -> string?
1616
Microsoft.AspNetCore.Http.ISession.TryGetValue(string! key, out byte[]? value) -> bool
1717
Microsoft.AspNetCore.Http.Features.FeatureCollection.FeatureCollection(int initialCapacity) -> void
18-
Microsoft.AspNetCore.Http.IResponseCookies.Append(System.Collections.Generic.IDictionary<string!, string!>! keyValuePairs, Microsoft.AspNetCore.Http.CookieOptions! options) -> void
18+
Microsoft.AspNetCore.Http.IResponseCookies.Append(System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string!, string!>>! keyValuePairs, Microsoft.AspNetCore.Http.CookieOptions! options) -> void

src/Http/Http/src/Internal/ResponseCookies.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Linq;
67
using Microsoft.AspNetCore.Http.Features;
78
using Microsoft.Extensions.DependencyInjection;
89
using Microsoft.Extensions.Logging;
@@ -89,7 +90,7 @@ public void Append(string key, string value, CookieOptions options)
8990
}
9091

9192
/// <inheritdoc />
92-
public void Append(IDictionary<string, string> keyValuePairs, CookieOptions options)
93+
public void Append(IEnumerable<KeyValuePair<string, string>> keyValuePairs, CookieOptions options)
9394
{
9495
if (options == null)
9596
{
@@ -126,17 +127,17 @@ public void Append(IDictionary<string, string> keyValuePairs, CookieOptions opti
126127
};
127128

128129
var cookierHeaderValue = setCookieHeaderValue.ToString()[1..];
129-
var cookies = new string[keyValuePairs.Count];
130+
var cookies = new string[keyValuePairs.Count()];
130131
var position = 0;
131132

132133
foreach (var keyValuePair in keyValuePairs)
133134
{
134-
cookies[position] = $"{keyValuePair.Key}={keyValuePair.Value}{cookierHeaderValue}";
135+
136+
cookies[position] = string.Concat(_enableCookieNameEncoding ? Uri.EscapeDataString(keyValuePair.Key) : keyValuePair.Key, "=", Uri.EscapeDataString(keyValuePair.Value), cookierHeaderValue);
135137
position++;
136138
}
137139

138140
Headers.Append(HeaderNames.SetCookie, cookies);
139-
140141
}
141142

142143
/// <inheritdoc />

src/Mvc/Mvc.ViewFeatures/test/CookieTempDataProviderTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ IEnumerator IEnumerable.GetEnumerator()
417417
return GetEnumerator();
418418
}
419419

420-
public void Append(IDictionary<string, string> keyValuePairs, CookieOptions options)
420+
public void Append(IEnumerable<KeyValuePair<string, string>> keyValuePairs, CookieOptions options)
421421
{
422422
foreach (var keyValuePair in keyValuePairs)
423423
{

src/Security/CookiePolicy/src/ResponseCookiesWrapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void Append(string key, string value, CookieOptions options)
153153
}
154154
}
155155

156-
public void Append(IDictionary<string, string> keyValuePairs, CookieOptions options)
156+
public void Append(IEnumerable<KeyValuePair<string, string>> keyValuePairs, CookieOptions options)
157157
{
158158
if (options == null)
159159
{

src/Security/CookiePolicy/test/CookiePolicyTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ public void Append(string key, string value, CookieOptions options)
486486
throw new NotImplementedException();
487487
}
488488

489-
public void Append(IDictionary<string, string> keyValuePairs, CookieOptions options)
489+
public void Append(IEnumerable<KeyValuePair<string, string>> keyValuePairs, CookieOptions options)
490490
{
491491
throw new NotImplementedException();
492492
}

src/Shared/ChunkingCookieManager/ChunkingCookieManager.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,19 @@ public void AppendResponseCookie(HttpContext context, string key, string? value,
208208
var dataSizePerCookie = ChunkSize.Value - templateLength - 3; // Budget 3 chars for the chunkid.
209209
var cookieChunkCount = (int)Math.Ceiling(value.Length * 1.0 / dataSizePerCookie);
210210

211-
IDictionary<string, string> keyValuePairs = new Dictionary<string, string>(cookieChunkCount)
211+
List<KeyValuePair<string, string>> keyValuePairs = new(cookieChunkCount)
212212
{
213-
[key] = ChunkCountPrefix + cookieChunkCount.ToString(CultureInfo.InvariantCulture)
213+
KeyValuePair.Create(key, ChunkCountPrefix + cookieChunkCount.ToString(CultureInfo.InvariantCulture))
214214
};
215215

216-
217216
var offset = 0;
218217
for (var chunkId = 1; chunkId <= cookieChunkCount; chunkId++)
219218
{
220219
var remainingLength = value.Length - offset;
221220
var length = Math.Min(dataSizePerCookie, remainingLength);
222221
var segment = value.Substring(offset, length);
223222
offset += length;
224-
keyValuePairs.Add(key + ChunkKeySuffix + chunkId.ToString(CultureInfo.InvariantCulture), segment);
223+
keyValuePairs.Add(KeyValuePair.Create(string.Concat(key, ChunkKeySuffix, chunkId.ToString(CultureInfo.InvariantCulture)), segment));
225224
}
226225

227226
responseCookies.Append(keyValuePairs, options);
@@ -307,15 +306,14 @@ public void DeleteCookie(HttpContext context, string key, CookieOptions options)
307306

308307
var responseCookies = context.Response.Cookies;
309308

310-
311-
IDictionary<string, string> keyValuePairs = new Dictionary<string, string>(chunks)
309+
List<KeyValuePair<string, string>> keyValuePairs = new(chunks)
312310
{
313-
[key] = string.Empty
311+
KeyValuePair.Create(key, string.Empty)
314312
};
315313

316314
for (var i = 1; i <= chunks; i++)
317315
{
318-
keyValuePairs.Add(key + "C" + i.ToString(CultureInfo.InvariantCulture), string.Empty);
316+
keyValuePairs.Add(KeyValuePair.Create(string.Concat(key, "C", i.ToString(CultureInfo.InvariantCulture)), string.Empty));
319317
}
320318

321319
responseCookies.Append(keyValuePairs, new CookieOptions()

0 commit comments

Comments
 (0)