From: Jan Jahoda Date: Wed, 12 Aug 2020 13:35:55 +0000 (+0200) Subject: FormUrlEncodedContent - make key non Nullable (#40267) X-Git-Tag: submit/tizen/20210909.063632~6052 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b977407c9ec8cd7f87ea9bbab8fb69ad45a747e1;p=platform%2Fupstream%2Fdotnet%2Fruntime.git FormUrlEncodedContent - make key non Nullable (#40267) As described in #38494, it is not easy to use Dictionary to create FormUrlEncodedContent instance. I revisited the code and it seems to me we shouldn't support nullable keys. Instead of null key we should use empty string. --- diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/FormUrlEncodedContent.cs b/src/libraries/System.Net.Http/src/System/Net/Http/FormUrlEncodedContent.cs index fe723de..0b684b1 100644 --- a/src/libraries/System.Net.Http/src/System/Net/Http/FormUrlEncodedContent.cs +++ b/src/libraries/System.Net.Http/src/System/Net/Http/FormUrlEncodedContent.cs @@ -12,13 +12,13 @@ namespace System.Net.Http { public class FormUrlEncodedContent : ByteArrayContent { - public FormUrlEncodedContent(IEnumerable> nameValueCollection) + public FormUrlEncodedContent(IEnumerable> nameValueCollection) : base(GetContentByteArray(nameValueCollection)) { Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded"); } - private static byte[] GetContentByteArray(IEnumerable> nameValueCollection) + private static byte[] GetContentByteArray(IEnumerable> nameValueCollection) { if (nameValueCollection == null) { @@ -27,7 +27,7 @@ namespace System.Net.Http // Encode and concatenate data StringBuilder builder = new StringBuilder(); - foreach (KeyValuePair pair in nameValueCollection) + foreach (KeyValuePair pair in nameValueCollection) { if (builder.Length > 0) {