diff --git a/samples/ExceptionHandlerSample/Startup.cs b/samples/ExceptionHandlerSample/Startup.cs index a143b167ba..f57adf61b2 100644 --- a/samples/ExceptionHandlerSample/Startup.cs +++ b/samples/ExceptionHandlerSample/Startup.cs @@ -1,9 +1,9 @@ using System; +using System.Text.Encodings.Web; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.Extensions.WebEncoders; namespace ExceptionHandlerSample { @@ -26,7 +26,7 @@ namespace ExceptionHandlerSample if (error != null) { // This error would not normally be exposed to the client - await context.Response.WriteAsync("
Error: " + HtmlEncoder.Default.HtmlEncode(error.Error.Message) + "
\r\n"); + await context.Response.WriteAsync("
Error: " + HtmlEncoder.Default.Encode(error.Error.Message) + "
\r\n"); } await context.Response.WriteAsync("
Home
\r\n"); await context.Response.WriteAsync("\r\n"); diff --git a/samples/StatusCodePagesSample/Startup.cs b/samples/StatusCodePagesSample/Startup.cs index 13b12e4b1c..5f0220db85 100644 --- a/samples/StatusCodePagesSample/Startup.cs +++ b/samples/StatusCodePagesSample/Startup.cs @@ -4,12 +4,12 @@ using System.Linq; using System.Net; using System.Text; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Features; -using Microsoft.Extensions.WebEncoders; namespace StatusCodePagesSample { @@ -63,11 +63,11 @@ namespace StatusCodePagesSample { var builder = new StringBuilder(); builder.AppendLine(""); - builder.AppendLine("An error occurred, Status Code: " + HtmlEncoder.Default.HtmlEncode(context.Request.Path.ToString().Substring(1)) + "
"); + builder.AppendLine("An error occurred, Status Code: " + HtmlEncoder.Default.Encode(context.Request.Path.ToString().Substring(1)) + "
"); var referrer = context.Request.Headers["referer"]; if (!string.IsNullOrEmpty(referrer)) { - builder.AppendLine("Retry " + WebUtility.HtmlEncode(referrer) + "
"); + builder.AppendLine("Retry " + WebUtility.HtmlEncode(referrer) + "
"); } builder.AppendLine(""); context.Response.ContentType = "text/html"; @@ -81,8 +81,8 @@ namespace StatusCodePagesSample var builder = new StringBuilder(); builder.AppendLine(""); builder.AppendLine("" + - HtmlEncoder.Default.HtmlEncode(context.Request.PathBase.ToString()) + "/missingpage/
"); + HtmlEncoder.Default.Encode(context.Request.PathBase.ToString()) + "/missingpage/\">" + + HtmlEncoder.Default.Encode(context.Request.PathBase.ToString()) + "/missingpage/
"); var space = string.Concat(Enumerable.Repeat(" ", 12)); builder.AppendFormat("
{0}{1}{2}
", "Status Code", space, "Status Code Pages"); diff --git a/src/Microsoft.AspNet.Diagnostics.Elm/HttpInfo.cs b/src/Microsoft.AspNet.Diagnostics.Elm/HttpInfo.cs index dee00626af..fd0de85c91 100644 --- a/src/Microsoft.AspNet.Diagnostics.Elm/HttpInfo.cs +++ b/src/Microsoft.AspNet.Diagnostics.Elm/HttpInfo.cs @@ -31,6 +31,6 @@ namespace Microsoft.AspNet.Diagnostics.Elm public QueryString Query { get; set; } - public IReadableStringCollection Cookies { get; set; } + public IRequestCookieCollection Cookies { get; set; } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Diagnostics.Entity/Views/DatabaseErrorPage.cs b/src/Microsoft.AspNet.Diagnostics.Entity/Views/DatabaseErrorPage.cs index a38a6435c7..7336db3947 100644 --- a/src/Microsoft.AspNet.Diagnostics.Entity/Views/DatabaseErrorPage.cs +++ b/src/Microsoft.AspNet.Diagnostics.Entity/Views/DatabaseErrorPage.cs @@ -34,12 +34,12 @@ using Microsoft.AspNet.Diagnostics.Entity.Views public string UrlEncode(string content) { - return UrlEncoder.UrlEncode(content); + return UrlEncoder.Encode(content); } public string JavaScriptEncode(string content) { - return JavaScriptStringEncoder.JavaScriptStringEncode(content); + return JavaScriptEncoder.Encode(content); } #line default diff --git a/src/Microsoft.AspNet.Diagnostics.Entity/Views/DatabaseErrorPage.cshtml b/src/Microsoft.AspNet.Diagnostics.Entity/Views/DatabaseErrorPage.cshtml index ccfe59278b..c1f181834f 100644 --- a/src/Microsoft.AspNet.Diagnostics.Entity/Views/DatabaseErrorPage.cshtml +++ b/src/Microsoft.AspNet.Diagnostics.Entity/Views/DatabaseErrorPage.cshtml @@ -13,12 +13,12 @@ public string UrlEncode(string content) { - return UrlEncoder.UrlEncode(content); + return UrlEncoder.Encode(content); } public string JavaScriptEncode(string content) { - return JavaScriptStringEncoder.JavaScriptStringEncode(content); + return JavaScriptEncoder.Encode(content); } } diff --git a/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPageModel.cs b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPageModel.cs index 2c7c3f6b26..9ba217b9a6 100644 --- a/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPageModel.cs +++ b/src/Microsoft.AspNet.Diagnostics/DeveloperExceptionPage/Views/ErrorPageModel.cs @@ -27,13 +27,13 @@ namespace Microsoft.AspNet.Diagnostics.Views /// Parsed query data. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")] - public IReadableStringCollection Query { get; set; } + public IQueryCollection Query { get; set; } /// /// Request cookies. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")] - public IReadableStringCollection Cookies { get; set; } + public IRequestCookieCollection Cookies { get; set; } /// /// Request headers. diff --git a/src/Microsoft.AspNet.Diagnostics/Views/BaseView.cs b/src/Microsoft.AspNet.Diagnostics/Views/BaseView.cs index 1d8010aa23..7ee4ed6448 100644 --- a/src/Microsoft.AspNet.Diagnostics/Views/BaseView.cs +++ b/src/Microsoft.AspNet.Diagnostics/Views/BaseView.cs @@ -9,6 +9,7 @@ using System.Globalization; using System.IO; using System.Linq; using System.Text; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNet.Http; using Microsoft.Extensions.WebEncoders; @@ -43,17 +44,17 @@ namespace Microsoft.AspNet.Diagnostics.Views /// /// Html encoder used to encode content. /// - protected IHtmlEncoder HtmlEncoder { get; set; } + protected HtmlEncoder HtmlEncoder { get; set; } /// /// Url encoder used to encode content. /// - protected IUrlEncoder UrlEncoder { get; set; } + protected UrlEncoder UrlEncoder { get; set; } /// /// JavaScript encoder used to encode content. /// - protected IJavaScriptStringEncoder JavaScriptStringEncoder { get; set; } + protected JavaScriptEncoder JavaScriptEncoder { get; set; } /// /// Execute an individual request @@ -67,7 +68,7 @@ namespace Microsoft.AspNet.Diagnostics.Views Output = new StreamWriter(Response.Body, Encoding.UTF8, 4096, leaveOpen: true); HtmlEncoder = context.ApplicationServices.GetHtmlEncoder(); UrlEncoder = context.ApplicationServices.GetUrlEncoder(); - JavaScriptStringEncoder = context.ApplicationServices.GetJavaScriptStringEncoder(); + JavaScriptEncoder = context.ApplicationServices.GetJavaScriptEncoder(); await ExecuteAsync(); Output.Dispose(); } @@ -272,7 +273,7 @@ namespace Microsoft.AspNet.Diagnostics.Views /// The to write. protected void WriteTo(TextWriter writer, string value) { - WriteLiteralTo(writer, HtmlEncoder.HtmlEncode(value)); + WriteLiteralTo(writer, HtmlEncoder.Encode(value)); } /// @@ -308,7 +309,7 @@ namespace Microsoft.AspNet.Diagnostics.Views return string.Join("
" + Environment.NewLine, input.Split(new[] { "\r\n" }, StringSplitOptions.None) .SelectMany(s => s.Split(new[] { '\r', '\n' }, StringSplitOptions.None)) - .Select(HtmlEncoder.HtmlEncode)); + .Select(HtmlEncoder.Encode)); } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Diagnostics/project.json b/src/Microsoft.AspNet.Diagnostics/project.json index e03f3200d8..e34a6ee13c 100644 --- a/src/Microsoft.AspNet.Diagnostics/project.json +++ b/src/Microsoft.AspNet.Diagnostics/project.json @@ -10,10 +10,10 @@ "Microsoft.AspNet.FileProviders.Physical": "1.0.0-*", "Microsoft.AspNet.Http.Extensions": "1.0.0-*", "Microsoft.AspNet.WebUtilities": "1.0.0-*", + "Microsoft.Extensions.Compilation.Abstractions": "1.0.0-*", "Microsoft.Extensions.Logging.Abstractions": "1.0.0-*", "Microsoft.Extensions.OptionsModel": "1.0.0-*", - "Microsoft.Extensions.Compilation.Abstractions": "1.0.0-*", - "Microsoft.Extensions.WebEncoders.Core": "1.0.0-*", + "Microsoft.Extensions.WebEncoders": "1.0.0-*", "System.Diagnostics.DiagnosticSource": "4.0.0-beta-*" }, "frameworks": { diff --git a/test/Microsoft.AspNet.Diagnostics.Entity.FunctionalTests/DatabaseErrorPageMiddlewareTest.cs b/test/Microsoft.AspNet.Diagnostics.Entity.FunctionalTests/DatabaseErrorPageMiddlewareTest.cs index 3233544ccc..92fa6cf3e2 100644 --- a/test/Microsoft.AspNet.Diagnostics.Entity.FunctionalTests/DatabaseErrorPageMiddlewareTest.cs +++ b/test/Microsoft.AspNet.Diagnostics.Entity.FunctionalTests/DatabaseErrorPageMiddlewareTest.cs @@ -7,6 +7,7 @@ using System.Data.SqlClient; using System.Linq; using System.Net; using System.Net.Http; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Diagnostics.Entity.FunctionalTests.Helpers; @@ -18,7 +19,6 @@ using Microsoft.Data.Entity; using Microsoft.Data.Entity.Infrastructure; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; -using Microsoft.Extensions.WebEncoders; using Xunit; namespace Microsoft.AspNet.Diagnostics.Entity.Tests @@ -209,7 +209,7 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests var content = await response.Content.ReadAsStringAsync(); // Ensure the url we're going to test is what the page is using in it's JavaScript - var javaScriptEncoder = new JavaScriptStringEncoder(); + var javaScriptEncoder = JavaScriptEncoder.Default; Assert.Contains("req.open(\"POST\", \"" + JavaScriptEncode(expectedMigrationsEndpoint) + "\", true);", content); Assert.Contains("var formBody = \"context=" + JavaScriptEncode(UrlEncode(expectedContextType)) + "\";", content); @@ -436,16 +436,16 @@ namespace Microsoft.AspNet.Diagnostics.Entity.Tests } } - private static UrlEncoder _urlEncoder = new UrlEncoder(); + private static UrlEncoder _urlEncoder = UrlEncoder.Default; private static string UrlEncode(string content) { - return _urlEncoder.UrlEncode(content); + return _urlEncoder.Encode(content); } - private static JavaScriptStringEncoder _javaScriptEncoder = new JavaScriptStringEncoder(); + private static JavaScriptEncoder _javaScriptEncoder = JavaScriptEncoder.Default; private static string JavaScriptEncode(string content) { - return _javaScriptEncoder.JavaScriptStringEncode(content); + return _javaScriptEncoder.Encode(content); } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Diagnostics.Tests/ElmMiddlewareTest.cs b/test/Microsoft.AspNet.Diagnostics.Tests/ElmMiddlewareTest.cs index b3b69b5b4f..c2d4059545 100644 --- a/test/Microsoft.AspNet.Diagnostics.Tests/ElmMiddlewareTest.cs +++ b/test/Microsoft.AspNet.Diagnostics.Tests/ElmMiddlewareTest.cs @@ -207,10 +207,10 @@ namespace Microsoft.AspNet.Diagnostics.Tests .Returns(new QueryString()); contextMock .SetupGet(c => c.Request.Query) - .Returns(new Mock().Object); + .Returns(new Mock().Object); contextMock .SetupGet(c => c.Request.Cookies) - .Returns(new Mock().Object); + .Returns(new Mock().Object); contextMock .Setup(c => c.Request.ReadFormAsync(It.IsAny())) .Returns(Task.FromResult(new Mock().Object)); diff --git a/test/Microsoft.AspNet.Diagnostics.Tests/RuntimeInfoMiddlewareTest.cs b/test/Microsoft.AspNet.Diagnostics.Tests/RuntimeInfoMiddlewareTest.cs index 7ce0bd4982..97fbab1f46 100644 --- a/test/Microsoft.AspNet.Diagnostics.Tests/RuntimeInfoMiddlewareTest.cs +++ b/test/Microsoft.AspNet.Diagnostics.Tests/RuntimeInfoMiddlewareTest.cs @@ -7,12 +7,13 @@ using System.IO; using System.Linq; using System.Reflection; using System.Text; +using System.Text.Encodings.Web; using System.Threading.Tasks; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.PlatformAbstractions; -using Microsoft.Extensions.WebEncoders; +using Microsoft.Extensions.WebEncoders.Testing; #if DNX451 using Moq; #endif @@ -204,7 +205,7 @@ namespace Microsoft.AspNet.Diagnostics.Tests contextMock .SetupGet(c => c.ApplicationServices) .Returns(new ServiceCollection(). - AddInstance(new CustomHtmlEncoder()). + AddInstance(new HtmlTestEncoder()). BuildServiceProvider()); // Act @@ -213,29 +214,11 @@ namespace Microsoft.AspNet.Diagnostics.Tests // Assert string response = Encoding.UTF8.GetString(buffer); - Assert.True(response.Contains("[LibInfo1]")); - Assert.True(response.Contains("[1.0.0-beta1]")); - Assert.True(response.Contains("[Path1]")); + Assert.True(response.Contains("HtmlEncode[[LibInfo1]]")); + Assert.True(response.Contains("HtmlEncode[[1.0.0-beta1]]")); + Assert.True(response.Contains("HtmlEncode[[Path1]]")); } } #endif - - private class CustomHtmlEncoder : IHtmlEncoder - { - public string HtmlEncode(string value) - { - return "[" + value + "]"; - } - - public void HtmlEncode(string value, int startIndex, int charCount, TextWriter output) - { - throw new NotImplementedException(); - } - - public void HtmlEncode(char[] value, int startIndex, int charCount, TextWriter output) - { - throw new NotImplementedException(); - } - } } }