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

Commit 90c13ad

Browse files
committed
Don't wrap the encoders.
1 parent e7e7032 commit 90c13ad

23 files changed

+215
-437
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Globalization;
77
using System.IO;
88
using System.Text;
9+
using System.Text.Encodings.Web;
910
using Microsoft.Extensions.WebEncoders;
1011

1112
namespace Microsoft.AspNet.Html.Abstractions
@@ -196,7 +197,7 @@ public HtmlEncodedString(string value)
196197
_value = value;
197198
}
198199

199-
public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
200+
public void WriteTo(TextWriter writer, HtmlEncoder encoder)
200201
{
201202
writer.Write(_value);
202203
}
@@ -205,7 +206,7 @@ private string DebuggerToString()
205206
{
206207
using (var writer = new StringWriter())
207208
{
208-
WriteTo(writer, HtmlEncoderWrapper.Default);
209+
WriteTo(writer, HtmlEncoder.Default);
209210
return writer.ToString();
210211
}
211212
}
@@ -233,7 +234,7 @@ public HtmlFormatString(IFormatProvider formatProvider, string format, object[]
233234
_args = args;
234235
}
235236

236-
public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
237+
public void WriteTo(TextWriter writer, HtmlEncoder encoder)
237238
{
238239
if (writer == null)
239240
{
@@ -253,7 +254,7 @@ private string DebuggerToString()
253254
{
254255
using (var writer = new StringWriter())
255256
{
256-
WriteTo(writer, HtmlEncoderWrapper.Default);
257+
WriteTo(writer, HtmlEncoder.Default);
257258
return writer.ToString();
258259
}
259260
}
@@ -268,10 +269,10 @@ private string DebuggerToString()
268269
// https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx#Format6_Example
269270
private class EncodingFormatProvider : IFormatProvider, ICustomFormatter
270271
{
271-
private readonly IHtmlEncoder _encoder;
272+
private readonly HtmlEncoder _encoder;
272273
private readonly IFormatProvider _formatProvider;
273274

274-
public EncodingFormatProvider(IFormatProvider formatProvider, IHtmlEncoder encoder)
275+
public EncodingFormatProvider(IFormatProvider formatProvider, HtmlEncoder encoder)
275276
{
276277
Debug.Assert(formatProvider != null);
277278
Debug.Assert(encoder != null);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +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 System.Text.Encodings.Web;
56
using Microsoft.Extensions.WebEncoders;
67

78
namespace Microsoft.AspNet.Html.Abstractions
@@ -16,7 +17,7 @@ public interface IHtmlContent
1617
/// to the specified <paramref name="writer"/>.
1718
/// </summary>
1819
/// <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);
20+
/// <param name="encoder">The <see cref="HtmlEncoder"/> which encodes the content to be written.</param>
21+
void WriteTo(TextWriter writer, HtmlEncoder encoder);
2122
}
2223
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Diagnostics;
77
using System.IO;
8+
using System.Text.Encodings.Web;
89
using Microsoft.AspNet.Html.Abstractions;
910
using Microsoft.Extensions.WebEncoders;
1011

@@ -64,7 +65,7 @@ public IHtmlContentBuilder Clear()
6465
}
6566

6667
/// <inheritdoc />
67-
public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
68+
public void WriteTo(TextWriter writer, HtmlEncoder encoder)
6869
{
6970
if (writer == null)
7071
{
@@ -100,7 +101,7 @@ private string DebuggerToString()
100101
{
101102
using (var writer = new StringWriter())
102103
{
103-
WriteTo(writer, HtmlEncoderWrapper.Default);
104+
WriteTo(writer, HtmlEncoder.Default);
104105
return writer.ToString();
105106
}
106107
}
@@ -116,7 +117,7 @@ public HtmlEncodedString(string value)
116117
_value = value;
117118
}
118119

119-
public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
120+
public void WriteTo(TextWriter writer, HtmlEncoder encoder)
120121
{
121122
writer.Write(_value);
122123
}

src/Microsoft.Extensions.WebEncoders.Core/EncoderExtensions.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using System;
54
using System.IO;
65

7-
namespace Microsoft.Extensions.WebEncoders
6+
namespace System.Text.Encodings.Web
87
{
98
/// <summary>
109
/// Helpful extension methods for the encoder classes.
@@ -18,14 +17,14 @@ public static class EncoderExtensions
1817
/// The encoded value is also safe for inclusion inside an HTML attribute
1918
/// as long as the attribute value is surrounded by single or double quotes.
2019
/// </remarks>
21-
public static void Encode(this IHtmlEncoder htmlEncoder, string value, TextWriter output)
20+
public static void Encode(this HtmlEncoder htmlEncoder, string value, TextWriter output)
2221
{
2322
if (htmlEncoder == null)
2423
{
2524
throw new ArgumentNullException(nameof(htmlEncoder));
2625
}
2726

28-
if (!String.IsNullOrEmpty(value))
27+
if (!string.IsNullOrEmpty(value))
2928
{
3029
htmlEncoder.Encode(output, value, 0, value.Length);
3130
}
@@ -34,14 +33,14 @@ public static void Encode(this IHtmlEncoder htmlEncoder, string value, TextWrite
3433
/// <summary>
3534
/// JavaScript-escapes a string and writes the result to the supplied output.
3635
/// </summary>
37-
public static void Encode(this IJavaScriptEncoder javaScriptEncoder, string value, TextWriter output)
36+
public static void Encode(this JavaScriptEncoder javaScriptEncoder, string value, TextWriter output)
3837
{
3938
if (javaScriptEncoder == null)
4039
{
4140
throw new ArgumentNullException(nameof(javaScriptEncoder));
4241
}
4342

44-
if (!String.IsNullOrEmpty(value))
43+
if (!string.IsNullOrEmpty(value))
4544
{
4645
javaScriptEncoder.Encode(output, value, 0, value.Length);
4746
}
@@ -54,14 +53,14 @@ public static void Encode(this IJavaScriptEncoder javaScriptEncoder, string valu
5453
/// The encoded value is safe for use in the segment, query, or
5554
/// fragment portion of a URI.
5655
/// </remarks>
57-
public static void Encode(this IUrlEncoder urlEncoder, string value, TextWriter output)
56+
public static void Encode(this UrlEncoder urlEncoder, string value, TextWriter output)
5857
{
5958
if (urlEncoder == null)
6059
{
6160
throw new ArgumentNullException(nameof(urlEncoder));
6261
}
6362

64-
if (!String.IsNullOrEmpty(value))
63+
if (!string.IsNullOrEmpty(value))
6564
{
6665
urlEncoder.Encode(output, value, 0, value.Length);
6766
}

src/Microsoft.Extensions.WebEncoders.Core/EncoderServiceProviderExtensions.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +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;
5+
using System.Text.Encodings.Web;
56

67
namespace Microsoft.Extensions.WebEncoders
78
{
@@ -17,9 +18,9 @@ public static class EncoderServiceProviderExtensions
1718
/// This method is guaranteed never to return null.
1819
/// It will return a default encoder instance if <paramref name="serviceProvider"/> does not contain one or is null.
1920
/// </remarks>
20-
public static IHtmlEncoder GetHtmlEncoder(this IServiceProvider serviceProvider)
21+
public static HtmlEncoder GetHtmlEncoder(this IServiceProvider serviceProvider)
2122
{
22-
return (IHtmlEncoder)serviceProvider?.GetService(typeof(IHtmlEncoder)) ?? HtmlEncoderWrapper.Default;
23+
return (HtmlEncoder)serviceProvider?.GetService(typeof(HtmlEncoder)) ?? HtmlEncoder.Default;
2324
}
2425

2526
/// <summary>
@@ -29,9 +30,9 @@ public static IHtmlEncoder GetHtmlEncoder(this IServiceProvider serviceProvider)
2930
/// This method is guaranteed never to return null.
3031
/// It will return a default encoder instance if <paramref name="serviceProvider"/> does not contain one or is null.
3132
/// </remarks>
32-
public static IJavaScriptEncoder GetJavaScriptEncoder(this IServiceProvider serviceProvider)
33+
public static JavaScriptEncoder GetJavaScriptEncoder(this IServiceProvider serviceProvider)
3334
{
34-
return (IJavaScriptEncoder)serviceProvider?.GetService(typeof(IJavaScriptEncoder)) ?? JavaScriptEncoderWrapper.Default;
35+
return (JavaScriptEncoder)serviceProvider?.GetService(typeof(JavaScriptEncoder)) ?? JavaScriptEncoder.Default;
3536
}
3637

3738
/// <summary>
@@ -41,9 +42,9 @@ public static IJavaScriptEncoder GetJavaScriptEncoder(this IServiceProvider serv
4142
/// This method is guaranteed never to return null.
4243
/// It will return a default encoder instance if <paramref name="serviceProvider"/> does not contain one or is null.
4344
/// </remarks>
44-
public static IUrlEncoder GetUrlEncoder(this IServiceProvider serviceProvider)
45+
public static UrlEncoder GetUrlEncoder(this IServiceProvider serviceProvider)
4546
{
46-
return (IUrlEncoder)serviceProvider?.GetService(typeof(IUrlEncoder)) ?? UrlEncoderWrapper.Default;
47+
return (UrlEncoder)serviceProvider?.GetService(typeof(UrlEncoder)) ?? UrlEncoder.Default;
4748
}
4849
}
4950
}

src/Microsoft.Extensions.WebEncoders.Core/HtmlEncoderWrapper.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/Microsoft.Extensions.WebEncoders.Core/IHtmlEncoder.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/Microsoft.Extensions.WebEncoders.Core/IJavaScriptEncoder.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/Microsoft.Extensions.WebEncoders.Core/IUrlEncoder.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)