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

Commit 66c0195

Browse files
committed
#391 Migrate to System.Text.Encoding.Web
1 parent e4bf2f3 commit 66c0195

File tree

78 files changed

+329
-36374
lines changed

Some content is hidden

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

78 files changed

+329
-36374
lines changed

HttpAbstractions.sln

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
Microsoft Visual Studio Solution File, Format Version 12.00
32
# Visual Studio 14
43
VisualStudioVersion = 14.0.23107.0
@@ -39,8 +38,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.WebEnc
3938
EndProject
4039
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.WebEncoders.Tests", "test\Microsoft.Extensions.WebEncoders.Tests\Microsoft.Extensions.WebEncoders.Tests.xproj", "{7AE2731D-43CD-4CF8-850A-4914DE2CE930}"
4140
EndProject
42-
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.WebEncoders.Core", "src\Microsoft.Extensions.WebEncoders.Core\Microsoft.Extensions.WebEncoders.Core.xproj", "{BE9112CB-D87D-4080-9CC3-24492D49CBE6}"
43-
EndProject
4441
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Html.Abstractions", "src\Microsoft.AspNet.Html.Abstractions\Microsoft.AspNet.Html.Abstractions.xproj", "{68A28E4A-3ADE-4187-9625-4FF185887CB3}"
4542
EndProject
4643
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{982F09D8-621E-4872-BA7B-BBDEA47D1EFD}"
@@ -231,18 +228,6 @@ Global
231228
{7AE2731D-43CD-4CF8-850A-4914DE2CE930}.Release|Mixed Platforms.Build.0 = Release|Any CPU
232229
{7AE2731D-43CD-4CF8-850A-4914DE2CE930}.Release|x86.ActiveCfg = Release|Any CPU
233230
{7AE2731D-43CD-4CF8-850A-4914DE2CE930}.Release|x86.Build.0 = Release|Any CPU
234-
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
235-
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
236-
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
237-
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
238-
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|x86.ActiveCfg = Debug|Any CPU
239-
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|x86.Build.0 = Debug|Any CPU
240-
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
241-
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|Any CPU.Build.0 = Release|Any CPU
242-
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
243-
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
244-
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|x86.ActiveCfg = Release|Any CPU
245-
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|x86.Build.0 = Release|Any CPU
246231
{68A28E4A-3ADE-4187-9625-4FF185887CB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
247232
{68A28E4A-3ADE-4187-9625-4FF185887CB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
248233
{68A28E4A-3ADE-4187-9625-4FF185887CB3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -324,7 +309,6 @@ Global
324309
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1} = {F31FF137-390C-49BF-A3BD-7C6ED3597C21}
325310
{DD2CE416-765E-4000-A03E-C2FF165DA1B6} = {A5A15F1C-885A-452A-A731-B0173DDBD913}
326311
{7AE2731D-43CD-4CF8-850A-4914DE2CE930} = {F31FF137-390C-49BF-A3BD-7C6ED3597C21}
327-
{BE9112CB-D87D-4080-9CC3-24492D49CBE6} = {A5A15F1C-885A-452A-A731-B0173DDBD913}
328312
{68A28E4A-3ADE-4187-9625-4FF185887CB3} = {A5A15F1C-885A-452A-A731-B0173DDBD913}
329313
{1D0764B4-1DEB-4232-A714-D4B7E846918A} = {982F09D8-621E-4872-BA7B-BBDEA47D1EFD}
330314
{2D187B88-94BD-4A39-AC97-F8F8B9363301} = {F31FF137-390C-49BF-A3BD-7C6ED3597C21}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Diagnostics;
66
using System.Globalization;
77
using System.IO;
8-
using Microsoft.Extensions.WebEncoders;
8+
using System.Text.Encodings.Web;
99

1010
namespace Microsoft.AspNet.Html.Abstractions
1111
{
@@ -197,7 +197,7 @@ public HtmlEncodedString(string value)
197197
_value = value;
198198
}
199199

200-
public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
200+
public void WriteTo(TextWriter writer, HtmlEncoder encoder)
201201
{
202202
writer.Write(_value);
203203
}
@@ -234,7 +234,7 @@ public HtmlFormatString(IFormatProvider formatProvider, string format, object[]
234234
_args = args;
235235
}
236236

237-
public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
237+
public void WriteTo(TextWriter writer, HtmlEncoder encoder)
238238
{
239239
if (writer == null)
240240
{
@@ -269,10 +269,10 @@ private string DebuggerToString()
269269
// https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx#Format6_Example
270270
private class EncodingFormatProvider : IFormatProvider, ICustomFormatter
271271
{
272-
private readonly IHtmlEncoder _encoder;
272+
private readonly HtmlEncoder _encoder;
273273
private readonly IFormatProvider _formatProvider;
274274

275-
public EncodingFormatProvider(IFormatProvider formatProvider, IHtmlEncoder encoder)
275+
public EncodingFormatProvider(IFormatProvider formatProvider, HtmlEncoder encoder)
276276
{
277277
Debug.Assert(formatProvider != null);
278278
Debug.Assert(encoder != null);
@@ -306,7 +306,7 @@ public string Format(string format, object arg, IFormatProvider formatProvider)
306306
var result = customFormatter.Format(format, arg, _formatProvider);
307307
if (result != null)
308308
{
309-
return _encoder.HtmlEncode(result);
309+
return _encoder.Encode(result);
310310
}
311311
}
312312

@@ -320,7 +320,7 @@ public string Format(string format, object arg, IFormatProvider formatProvider)
320320
var result = formattable.ToString(format, _formatProvider);
321321
if (result != null)
322322
{
323-
return _encoder.HtmlEncode(result);
323+
return _encoder.Encode(result);
324324
}
325325
}
326326

@@ -330,7 +330,7 @@ public string Format(string format, object arg, IFormatProvider formatProvider)
330330
var result = arg.ToString();
331331
if (result != null)
332332
{
333-
return _encoder.HtmlEncode(result);
333+
return _encoder.Encode(result);
334334
}
335335
}
336336

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.IO;
5-
using Microsoft.Extensions.WebEncoders;
5+
using System.Text.Encodings.Web;
66

77
namespace Microsoft.AspNet.Html.Abstractions
88
{
@@ -16,7 +16,7 @@ public interface IHtmlContent
1616
/// to the specified <paramref name="writer"/>.
1717
/// </summary>
1818
/// <param name="writer">The <see cref="TextWriter"/> to which the content is written.</param>
19-
/// <param name="encoder">The <see cref="IHtmlEncoder"/> which encodes the content to be written.</param>
20-
void WriteTo(TextWriter writer, IHtmlEncoder encoder);
19+
/// <param name="encoder">The <see cref="HtmlEncoder"/> which encodes the content to be written.</param>
20+
void WriteTo(TextWriter writer, HtmlEncoder encoder);
2121
}
2222
}

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@
99
"warningsAsErrors": true
1010
},
1111
"dependencies": {
12-
"Microsoft.Extensions.WebEncoders.Core": "1.0.0-*"
12+
"System.Text.Encodings.Web": "4.0.0-beta-*"
1313
},
1414
"frameworks": {
15-
"net451": {},
15+
"net451": {
16+
"frameworkAssemblies": {
17+
"System.IO": "",
18+
"System.Runtime": ""
19+
}
20+
},
1621
"dotnet5.4": {
1722
"dependencies": {
1823
"System.Resources.ResourceManager": "4.0.1-beta-*"

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: 26 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());
@@ -158,9 +167,9 @@ public static QueryString Create(IEnumerable<KeyValuePair<string, StringValues>>
158167
{
159168
builder.Append(first ? "?" : "&");
160169
first = false;
161-
builder.Append(UrlEncoder.Default.UrlEncode(pair.Key));
170+
builder.Append(UrlEncoder.Default.Encode(pair.Key));
162171
builder.Append("=");
163-
builder.Append(UrlEncoder.Default.UrlEncode(value));
172+
builder.Append(UrlEncoder.Default.Encode(value));
164173
}
165174
}
166175

@@ -184,16 +193,25 @@ public QueryString Add(QueryString other)
184193

185194
public QueryString Add(string name, string value)
186195
{
196+
if (name == null)
197+
{
198+
throw new ArgumentNullException(nameof(name));
199+
}
200+
if (value == null)
201+
{
202+
throw new ArgumentNullException(nameof(value));
203+
}
204+
187205
if (!HasValue || Value.Equals("?", StringComparison.Ordinal))
188206
{
189207
return Create(name, value);
190208
}
191209

192210
var builder = new StringBuilder(Value);
193211
builder.Append("&");
194-
builder.Append(UrlEncoder.Default.UrlEncode(name));
212+
builder.Append(UrlEncoder.Default.Encode(name));
195213
builder.Append("=");
196-
builder.Append(UrlEncoder.Default.UrlEncode(value));
214+
builder.Append(UrlEncoder.Default.Encode(value));
197215
return new QueryString(builder.ToString());
198216
}
199217

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.Http/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"dotnet5.4": {
2020
"dependencies": {
2121
"System.Diagnostics.Debug": "4.0.11-beta-*",
22-
"System.Text.Encoding": "4.0.11-beta-*"
22+
"System.Text.Encoding": "4.0.11-beta-*",
23+
"System.Threading": "4.0.11-beta-*"
2324
}
2425
}
2526
}

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

0 commit comments

Comments
 (0)