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

Migrate to System.Text.Encoding.Web #449

Merged
merged 1 commit into from
Oct 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions HttpAbstractions.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
Expand Down Expand Up @@ -39,8 +38,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Extensions.WebEnc
EndProject
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}"
EndProject
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}"
EndProject
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}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{982F09D8-621E-4872-BA7B-BBDEA47D1EFD}"
Expand Down Expand Up @@ -231,18 +228,6 @@ Global
{7AE2731D-43CD-4CF8-850A-4914DE2CE930}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{7AE2731D-43CD-4CF8-850A-4914DE2CE930}.Release|x86.ActiveCfg = Release|Any CPU
{7AE2731D-43CD-4CF8-850A-4914DE2CE930}.Release|x86.Build.0 = Release|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|x86.ActiveCfg = Debug|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Debug|x86.Build.0 = Debug|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|Any CPU.Build.0 = Release|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|x86.ActiveCfg = Release|Any CPU
{BE9112CB-D87D-4080-9CC3-24492D49CBE6}.Release|x86.Build.0 = Release|Any CPU
{68A28E4A-3ADE-4187-9625-4FF185887CB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{68A28E4A-3ADE-4187-9625-4FF185887CB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{68A28E4A-3ADE-4187-9625-4FF185887CB3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -324,7 +309,6 @@ Global
{E6BB7AD1-BD10-4A23-B780-F4A86ADF00D1} = {F31FF137-390C-49BF-A3BD-7C6ED3597C21}
{DD2CE416-765E-4000-A03E-C2FF165DA1B6} = {A5A15F1C-885A-452A-A731-B0173DDBD913}
{7AE2731D-43CD-4CF8-850A-4914DE2CE930} = {F31FF137-390C-49BF-A3BD-7C6ED3597C21}
{BE9112CB-D87D-4080-9CC3-24492D49CBE6} = {A5A15F1C-885A-452A-A731-B0173DDBD913}
{68A28E4A-3ADE-4187-9625-4FF185887CB3} = {A5A15F1C-885A-452A-A731-B0173DDBD913}
{1D0764B4-1DEB-4232-A714-D4B7E846918A} = {982F09D8-621E-4872-BA7B-BBDEA47D1EFD}
{2D187B88-94BD-4A39-AC97-F8F8B9363301} = {F31FF137-390C-49BF-A3BD-7C6ED3597C21}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System.Diagnostics;
using System.Globalization;
using System.IO;
using Microsoft.Extensions.WebEncoders;
using System.Text.Encodings.Web;

namespace Microsoft.AspNet.Html.Abstractions
{
Expand Down Expand Up @@ -197,7 +197,7 @@ public HtmlEncodedString(string value)
_value = value;
}

public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
public void WriteTo(TextWriter writer, HtmlEncoder encoder)
{
writer.Write(_value);
}
Expand Down Expand Up @@ -234,7 +234,7 @@ public HtmlFormatString(IFormatProvider formatProvider, string format, object[]
_args = args;
}

public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
public void WriteTo(TextWriter writer, HtmlEncoder encoder)
{
if (writer == null)
{
Expand Down Expand Up @@ -269,10 +269,10 @@ private string DebuggerToString()
// https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx#Format6_Example
private class EncodingFormatProvider : IFormatProvider, ICustomFormatter
{
private readonly IHtmlEncoder _encoder;
private readonly HtmlEncoder _encoder;
private readonly IFormatProvider _formatProvider;

public EncodingFormatProvider(IFormatProvider formatProvider, IHtmlEncoder encoder)
public EncodingFormatProvider(IFormatProvider formatProvider, HtmlEncoder encoder)
{
Debug.Assert(formatProvider != null);
Debug.Assert(encoder != null);
Expand Down Expand Up @@ -306,7 +306,7 @@ public string Format(string format, object arg, IFormatProvider formatProvider)
var result = customFormatter.Format(format, arg, _formatProvider);
if (result != null)
{
return _encoder.HtmlEncode(result);
return _encoder.Encode(result);
}
}

Expand All @@ -320,7 +320,7 @@ public string Format(string format, object arg, IFormatProvider formatProvider)
var result = formattable.ToString(format, _formatProvider);
if (result != null)
{
return _encoder.HtmlEncode(result);
return _encoder.Encode(result);
}
}

Expand All @@ -330,7 +330,7 @@ public string Format(string format, object arg, IFormatProvider formatProvider)
var result = arg.ToString();
if (result != null)
{
return _encoder.HtmlEncode(result);
return _encoder.Encode(result);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.AspNet.Html.Abstractions/IHtmlContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.IO;
using Microsoft.Extensions.WebEncoders;
using System.Text.Encodings.Web;

namespace Microsoft.AspNet.Html.Abstractions
{
Expand All @@ -16,7 +16,7 @@ public interface IHtmlContent
/// to the specified <paramref name="writer"/>.
/// </summary>
/// <param name="writer">The <see cref="TextWriter"/> to which the content is written.</param>
/// <param name="encoder">The <see cref="IHtmlEncoder"/> which encodes the content to be written.</param>
void WriteTo(TextWriter writer, IHtmlEncoder encoder);
/// <param name="encoder">The <see cref="HtmlEncoder"/> which encodes the content to be written.</param>
void WriteTo(TextWriter writer, HtmlEncoder encoder);
}
}
9 changes: 7 additions & 2 deletions src/Microsoft.AspNet.Html.Abstractions/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@
"warningsAsErrors": true
},
"dependencies": {
"Microsoft.Extensions.WebEncoders.Core": "1.0.0-*"
"System.Text.Encodings.Web": "4.0.0-beta-*"
},
"frameworks": {
"net451": {},
"net451": {
"frameworkAssemblies": {
"System.IO": "",
"System.Runtime": ""
}
},
"dotnet5.4": {
"dependencies": {
"System.Resources.ResourceManager": "4.0.1-beta-*"
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.AspNet.Http.Abstractions/PathString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using System;
using System.Linq;
using Microsoft.Extensions.WebEncoders;
using System.Text.Encodings.Web;

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

/// <summary>
Expand Down
34 changes: 26 additions & 8 deletions src/Microsoft.AspNet.Http.Abstractions/QueryString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Encodings.Web;
using Microsoft.Extensions.Primitives;
using Microsoft.Extensions.WebEncoders;

namespace Microsoft.AspNet.Http
{
Expand Down Expand Up @@ -119,7 +119,16 @@ public static QueryString FromUriComponent(Uri uri)
/// <returns>The resulting QueryString</returns>
public static QueryString Create(string name, string value)
{
return new QueryString("?" + UrlEncoder.Default.UrlEncode(name) + '=' + UrlEncoder.Default.UrlEncode(value));
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}

return new QueryString("?" + UrlEncoder.Default.Encode(name) + '=' + UrlEncoder.Default.Encode(value));
}

/// <summary>
Expand All @@ -135,9 +144,9 @@ public static QueryString Create(IEnumerable<KeyValuePair<string, string>> param
{
builder.Append(first ? "?" : "&");
first = false;
builder.Append(UrlEncoder.Default.UrlEncode(pair.Key));
builder.Append(UrlEncoder.Default.Encode(pair.Key));
builder.Append("=");
builder.Append(UrlEncoder.Default.UrlEncode(pair.Value));
builder.Append(UrlEncoder.Default.Encode(pair.Value));
}

return new QueryString(builder.ToString());
Expand All @@ -158,9 +167,9 @@ public static QueryString Create(IEnumerable<KeyValuePair<string, StringValues>>
{
builder.Append(first ? "?" : "&");
first = false;
builder.Append(UrlEncoder.Default.UrlEncode(pair.Key));
builder.Append(UrlEncoder.Default.Encode(pair.Key));
builder.Append("=");
builder.Append(UrlEncoder.Default.UrlEncode(value));
builder.Append(UrlEncoder.Default.Encode(value));
}
}

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

public QueryString Add(string name, string value)
{
if (name == null)
{
throw new ArgumentNullException(nameof(name));
}
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}

if (!HasValue || Value.Equals("?", StringComparison.Ordinal))
{
return Create(name, value);
}

var builder = new StringBuilder(Value);
builder.Append("&");
builder.Append(UrlEncoder.Default.UrlEncode(name));
builder.Append(UrlEncoder.Default.Encode(name));
builder.Append("=");
builder.Append(UrlEncoder.Default.UrlEncode(value));
builder.Append(UrlEncoder.Default.Encode(value));
return new QueryString(builder.ToString());
}

Expand Down
12 changes: 9 additions & 3 deletions src/Microsoft.AspNet.Http.Abstractions/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@
"type": "build",
"version": "1.0.0-*"
},
"Microsoft.Extensions.WebEncoders.Core": "1.0.0-*"
"System.Text.Encodings.Web": "4.0.0-beta-*"
},
"frameworks": {
"net451": {},
"net451": {
"frameworkAssemblies": {
"System.IO": "",
"System.Runtime": ""
}
},
"dotnet5.4": {
"dependencies": {
"System.Collections": "4.0.11-beta-*",
"System.ComponentModel": "4.0.1-beta-*",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, is this actually used? I'm curious for what...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

System.Text.Encodings.Web seems to require it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't the transitive dependency solve that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should...

"System.Diagnostics.Tools": "4.0.1-beta-*",
"System.Globalization": "4.0.11-beta-*",
"System.Globalization.Extensions": "4.0.1-beta-*",
Expand All @@ -38,4 +44,4 @@
}
}
}
}
}
6 changes: 3 additions & 3 deletions src/Microsoft.AspNet.Http.Extensions/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.WebEncoders;
using System.Text.Encodings.Web;

namespace Microsoft.AspNet.Http.Extensions
{
Expand Down Expand Up @@ -45,9 +45,9 @@ public override string ToString()
var pair = _params[i];
builder.Append(first ? "?" : "&");
first = false;
builder.Append(UrlEncoder.Default.UrlEncode(pair.Key));
builder.Append(UrlEncoder.Default.Encode(pair.Key));
builder.Append("=");
builder.Append(UrlEncoder.Default.UrlEncode(pair.Value));
builder.Append(UrlEncoder.Default.Encode(pair.Value));
}

return builder.ToString();
Expand Down
3 changes: 1 addition & 2 deletions src/Microsoft.AspNet.Http.Extensions/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
},
"dependencies": {
"Microsoft.AspNet.Http.Abstractions": "1.0.0-*",
"Microsoft.Extensions.WebEncoders.Core": "1.0.0-*",
"Microsoft.Net.Http.Headers": "1.0.0-*"
},
"frameworks": {
Expand All @@ -23,4 +22,4 @@
}
}
}
}
}
14 changes: 7 additions & 7 deletions src/Microsoft.AspNet.Http/ResponseCookies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

using System;
using System.Linq;
using System.Text.Encodings.Web;
using Microsoft.Extensions.Primitives;
using Microsoft.Extensions.WebEncoders;
using Microsoft.Net.Http.Headers;

namespace Microsoft.AspNet.Http.Internal
Expand Down Expand Up @@ -38,8 +38,8 @@ public ResponseCookies(IHeaderDictionary headers)
public void Append(string key, string value)
{
var setCookieHeaderValue = new SetCookieHeaderValue(
UrlEncoder.Default.UrlEncode(key),
UrlEncoder.Default.UrlEncode(value))
UrlEncoder.Default.Encode(key),
UrlEncoder.Default.Encode(value))
{
Path = "/"
};
Expand All @@ -61,8 +61,8 @@ public void Append(string key, string value, CookieOptions options)
}

var setCookieHeaderValue = new SetCookieHeaderValue(
UrlEncoder.Default.UrlEncode(key),
UrlEncoder.Default.UrlEncode(value))
UrlEncoder.Default.Encode(key),
UrlEncoder.Default.Encode(value))
{
Domain = options.Domain,
Path = options.Path,
Expand All @@ -80,7 +80,7 @@ public void Append(string key, string value, CookieOptions options)
/// <param name="key"></param>
public void Delete(string key)
{
var encodedKeyPlusEquals = UrlEncoder.Default.UrlEncode(key) + "=";
var encodedKeyPlusEquals = UrlEncoder.Default.Encode(key) + "=";
Func<string, bool> predicate = value => value.StartsWith(encodedKeyPlusEquals, StringComparison.OrdinalIgnoreCase);

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

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

Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.AspNet.Http/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"dotnet5.4": {
"dependencies": {
"System.Diagnostics.Debug": "4.0.11-beta-*",
"System.Text.Encoding": "4.0.11-beta-*"
"System.Text.Encoding": "4.0.11-beta-*",
"System.Threading": "4.0.11-beta-*"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.AspNet.WebUtilities/QueryHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.Encodings.Web;
using Microsoft.Extensions.Primitives;
using Microsoft.Extensions.WebEncoders;

namespace Microsoft.AspNet.WebUtilities
{
Expand Down Expand Up @@ -92,9 +92,9 @@ private static string AddQueryString(
foreach (var parameter in queryString)
{
sb.Append(hasQuery ? '&' : '?');
sb.Append(UrlEncoder.Default.UrlEncode(parameter.Key));
sb.Append(UrlEncoder.Default.Encode(parameter.Key));
sb.Append('=');
sb.Append(UrlEncoder.Default.UrlEncode(parameter.Value));
sb.Append(UrlEncoder.Default.Encode(parameter.Value));
hasQuery = true;
}

Expand Down
Loading