Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Commit 273695a

Browse files
committed
#391 Migrate to System.Text.Encoding.Web
1 parent 018f3d1 commit 273695a

File tree

61 files changed

+240
-35877
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+240
-35877
lines changed

src/Microsoft.AspNet.Html.Abstractions/HtmlContentBuilderExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private string DebuggerToString()
206206
{
207207
using (var writer = new StringWriter())
208208
{
209-
WriteTo(writer, HtmlEncoder.Default);
209+
WriteTo(writer, HtmlEncoderWrapper.Default);
210210
return writer.ToString();
211211
}
212212
}
@@ -254,7 +254,7 @@ private string DebuggerToString()
254254
{
255255
using (var writer = new StringWriter())
256256
{
257-
WriteTo(writer, HtmlEncoder.Default);
257+
WriteTo(writer, HtmlEncoderWrapper.Default);
258258
return writer.ToString();
259259
}
260260
}

src/Microsoft.AspNet.Http.Abstractions/PathString.cs

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

44
using System;
55
using System.Linq;
6-
using Microsoft.Extensions.WebEncoders;
6+
using System.Text.Encodings.Web;
77

88
namespace Microsoft.AspNet.Http
99
{
@@ -66,7 +66,7 @@ public override string ToString()
6666
public string ToUriComponent()
6767
{
6868
// TODO: Measure the cost of this escaping and consider optimizing.
69-
return HasValue ? string.Join("/", _value.Split('/').Select(UrlEncoder.Default.UrlEncode)) : string.Empty;
69+
return HasValue ? string.Join("/", _value.Split('/').Select(UrlEncoder.Default.Encode)) : string.Empty;
7070
}
7171

7272
/// <summary>

src/Microsoft.AspNet.Http.Abstractions/QueryString.cs

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Text;
7+
using System.Text.Encodings.Web;
78
using Microsoft.Extensions.Primitives;
8-
using Microsoft.Extensions.WebEncoders;
99

1010
namespace Microsoft.AspNet.Http
1111
{
@@ -119,7 +119,16 @@ public static QueryString FromUriComponent(Uri uri)
119119
/// <returns>The resulting QueryString</returns>
120120
public static QueryString Create(string name, string value)
121121
{
122-
return new QueryString("?" + UrlEncoder.Default.UrlEncode(name) + '=' + UrlEncoder.Default.UrlEncode(value));
122+
if (name == null)
123+
{
124+
throw new ArgumentNullException(nameof(name));
125+
}
126+
if (value == null)
127+
{
128+
throw new ArgumentNullException(nameof(value));
129+
}
130+
131+
return new QueryString("?" + UrlEncoder.Default.Encode(name) + '=' + UrlEncoder.Default.Encode(value));
123132
}
124133

125134
/// <summary>
@@ -135,9 +144,9 @@ public static QueryString Create(IEnumerable<KeyValuePair<string, string>> param
135144
{
136145
builder.Append(first ? "?" : "&");
137146
first = false;
138-
builder.Append(UrlEncoder.Default.UrlEncode(pair.Key));
147+
builder.Append(UrlEncoder.Default.Encode(pair.Key));
139148
builder.Append("=");
140-
builder.Append(UrlEncoder.Default.UrlEncode(pair.Value));
149+
builder.Append(UrlEncoder.Default.Encode(pair.Value));
141150
}
142151

143152
return new QueryString(builder.ToString());
@@ -154,13 +163,23 @@ public static QueryString Create(IEnumerable<KeyValuePair<string, StringValues>>
154163
bool first = true;
155164
foreach (var pair in parameters)
156165
{
166+
if (pair.Key == null)
167+
{
168+
throw new ArgumentNullException(nameof(pair.Key));
169+
}
170+
157171
foreach (var value in pair.Value)
158172
{
173+
if (value == null)
174+
{
175+
throw new ArgumentNullException(nameof(value));
176+
}
177+
159178
builder.Append(first ? "?" : "&");
160179
first = false;
161-
builder.Append(UrlEncoder.Default.UrlEncode(pair.Key));
180+
builder.Append(UrlEncoder.Default.Encode(pair.Key));
162181
builder.Append("=");
163-
builder.Append(UrlEncoder.Default.UrlEncode(value));
182+
builder.Append(UrlEncoder.Default.Encode(value));
164183
}
165184
}
166185

@@ -184,16 +203,25 @@ public QueryString Add(QueryString other)
184203

185204
public QueryString Add(string name, string value)
186205
{
206+
if (name == null)
207+
{
208+
throw new ArgumentNullException(nameof(name));
209+
}
210+
if (value == null)
211+
{
212+
throw new ArgumentNullException(nameof(value));
213+
}
214+
187215
if (!HasValue || Value.Equals("?", StringComparison.Ordinal))
188216
{
189217
return Create(name, value);
190218
}
191219

192220
var builder = new StringBuilder(Value);
193221
builder.Append("&");
194-
builder.Append(UrlEncoder.Default.UrlEncode(name));
222+
builder.Append(UrlEncoder.Default.Encode(name));
195223
builder.Append("=");
196-
builder.Append(UrlEncoder.Default.UrlEncode(value));
224+
builder.Append(UrlEncoder.Default.Encode(value));
197225
return new QueryString(builder.ToString());
198226
}
199227

src/Microsoft.AspNet.Http.Abstractions/project.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,19 @@
1414
"type": "build",
1515
"version": "1.0.0-*"
1616
},
17-
"Microsoft.Extensions.WebEncoders.Core": "1.0.0-*"
17+
"System.Text.Encodings.Web": "4.0.0-beta-*"
1818
},
1919
"frameworks": {
20-
"net451": {},
20+
"net451": {
21+
"frameworkAssemblies": {
22+
"System.IO": "",
23+
"System.Runtime": ""
24+
}
25+
},
2126
"dotnet5.4": {
2227
"dependencies": {
2328
"System.Collections": "4.0.11-beta-*",
29+
"System.ComponentModel": "4.0.1-beta-*",
2430
"System.Diagnostics.Tools": "4.0.1-beta-*",
2531
"System.Globalization": "4.0.11-beta-*",
2632
"System.Globalization.Extensions": "4.0.1-beta-*",
@@ -38,4 +44,4 @@
3844
}
3945
}
4046
}
41-
}
47+
}

src/Microsoft.AspNet.Http.Extensions/QueryBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Collections;
55
using System.Collections.Generic;
66
using System.Text;
7-
using Microsoft.Extensions.WebEncoders;
7+
using System.Text.Encodings.Web;
88

99
namespace Microsoft.AspNet.Http.Extensions
1010
{
@@ -45,9 +45,9 @@ public override string ToString()
4545
var pair = _params[i];
4646
builder.Append(first ? "?" : "&");
4747
first = false;
48-
builder.Append(UrlEncoder.Default.UrlEncode(pair.Key));
48+
builder.Append(UrlEncoder.Default.Encode(pair.Key));
4949
builder.Append("=");
50-
builder.Append(UrlEncoder.Default.UrlEncode(pair.Value));
50+
builder.Append(UrlEncoder.Default.Encode(pair.Value));
5151
}
5252

5353
return builder.ToString();

src/Microsoft.AspNet.Http.Extensions/project.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
},
1111
"dependencies": {
1212
"Microsoft.AspNet.Http.Abstractions": "1.0.0-*",
13-
"Microsoft.Extensions.WebEncoders.Core": "1.0.0-*",
1413
"Microsoft.Net.Http.Headers": "1.0.0-*"
1514
},
1615
"frameworks": {
@@ -23,4 +22,4 @@
2322
}
2423
}
2524
}
26-
}
25+
}

src/Microsoft.AspNet.Http/ResponseCookies.cs

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

44
using System;
55
using System.Linq;
6+
using System.Text.Encodings.Web;
67
using Microsoft.Extensions.Primitives;
7-
using Microsoft.Extensions.WebEncoders;
88
using Microsoft.Net.Http.Headers;
99

1010
namespace Microsoft.AspNet.Http.Internal
@@ -38,8 +38,8 @@ public ResponseCookies(IHeaderDictionary headers)
3838
public void Append(string key, string value)
3939
{
4040
var setCookieHeaderValue = new SetCookieHeaderValue(
41-
UrlEncoder.Default.UrlEncode(key),
42-
UrlEncoder.Default.UrlEncode(value))
41+
UrlEncoder.Default.Encode(key),
42+
UrlEncoder.Default.Encode(value))
4343
{
4444
Path = "/"
4545
};
@@ -61,8 +61,8 @@ public void Append(string key, string value, CookieOptions options)
6161
}
6262

6363
var setCookieHeaderValue = new SetCookieHeaderValue(
64-
UrlEncoder.Default.UrlEncode(key),
65-
UrlEncoder.Default.UrlEncode(value))
64+
UrlEncoder.Default.Encode(key),
65+
UrlEncoder.Default.Encode(value))
6666
{
6767
Domain = options.Domain,
6868
Path = options.Path,
@@ -80,7 +80,7 @@ public void Append(string key, string value, CookieOptions options)
8080
/// <param name="key"></param>
8181
public void Delete(string key)
8282
{
83-
var encodedKeyPlusEquals = UrlEncoder.Default.UrlEncode(key) + "=";
83+
var encodedKeyPlusEquals = UrlEncoder.Default.Encode(key) + "=";
8484
Func<string, bool> predicate = value => value.StartsWith(encodedKeyPlusEquals, StringComparison.OrdinalIgnoreCase);
8585

8686
StringValues deleteCookies = encodedKeyPlusEquals + "; expires=Thu, 01-Jan-1970 00:00:00 GMT";
@@ -107,7 +107,7 @@ public void Delete(string key, CookieOptions options)
107107
throw new ArgumentNullException(nameof(options));
108108
}
109109

110-
var encodedKeyPlusEquals = UrlEncoder.Default.UrlEncode(key) + "=";
110+
var encodedKeyPlusEquals = UrlEncoder.Default.Encode(key) + "=";
111111
bool domainHasValue = !string.IsNullOrEmpty(options.Domain);
112112
bool pathHasValue = !string.IsNullOrEmpty(options.Path);
113113

src/Microsoft.AspNet.WebUtilities/QueryHelpers.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Text;
7+
using System.Text.Encodings.Web;
78
using Microsoft.Extensions.Primitives;
8-
using Microsoft.Extensions.WebEncoders;
99

1010
namespace Microsoft.AspNet.WebUtilities
1111
{
@@ -92,9 +92,9 @@ private static string AddQueryString(
9292
foreach (var parameter in queryString)
9393
{
9494
sb.Append(hasQuery ? '&' : '?');
95-
sb.Append(UrlEncoder.Default.UrlEncode(parameter.Key));
95+
sb.Append(UrlEncoder.Default.Encode(parameter.Key));
9696
sb.Append('=');
97-
sb.Append(UrlEncoder.Default.UrlEncode(parameter.Value));
97+
sb.Append(UrlEncoder.Default.Encode(parameter.Value));
9898
hasQuery = true;
9999
}
100100

src/Microsoft.AspNet.WebUtilities/project.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010
},
1111
"dependencies": {
1212
"Microsoft.Extensions.Primitives": "1.0.0-*",
13-
"Microsoft.Extensions.WebEncoders.Core": "1.0.0-*"
13+
"System.Text.Encodings.Web": "4.0.0-beta-*"
1414
},
1515
"frameworks": {
16-
"net451": {},
16+
"net451": {
17+
"frameworkAssemblies": {
18+
"System.Runtime": ""
19+
}
20+
},
1721
"dotnet5.4": {
1822
"dependencies": {
1923
"System.Collections": "4.0.11-beta-*",

src/Microsoft.Extensions.BufferedHtmlContent.Sources/BufferedHtmlContent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private string DebuggerToString()
100100
{
101101
using (var writer = new StringWriter())
102102
{
103-
WriteTo(writer, HtmlEncoder.Default);
103+
WriteTo(writer, HtmlEncoderWrapper.Default);
104104
return writer.ToString();
105105
}
106106
}

0 commit comments

Comments
 (0)