React to WebEncoders and Http.Abstractions changes.
This commit is contained in:
parent
5e0fa0773d
commit
c239b67368
|
|
@ -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("<br>Error: " + HtmlEncoder.Default.HtmlEncode(error.Error.Message) + "<br>\r\n");
|
||||
await context.Response.WriteAsync("<br>Error: " + HtmlEncoder.Default.Encode(error.Error.Message) + "<br>\r\n");
|
||||
}
|
||||
await context.Response.WriteAsync("<br><a href=\"/\">Home</a><br>\r\n");
|
||||
await context.Response.WriteAsync("</body></html>\r\n");
|
||||
|
|
|
|||
|
|
@ -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("<html><body>");
|
||||
builder.AppendLine("An error occurred, Status Code: " + HtmlEncoder.Default.HtmlEncode(context.Request.Path.ToString().Substring(1)) + "<br>");
|
||||
builder.AppendLine("An error occurred, Status Code: " + HtmlEncoder.Default.Encode(context.Request.Path.ToString().Substring(1)) + "<br>");
|
||||
var referrer = context.Request.Headers["referer"];
|
||||
if (!string.IsNullOrEmpty(referrer))
|
||||
{
|
||||
builder.AppendLine("<a href=\"" + HtmlEncoder.Default.HtmlEncode(referrer) + "\">Retry " + WebUtility.HtmlEncode(referrer) + "</a><br>");
|
||||
builder.AppendLine("<a href=\"" + HtmlEncoder.Default.Encode(referrer) + "\">Retry " + WebUtility.HtmlEncode(referrer) + "</a><br>");
|
||||
}
|
||||
builder.AppendLine("</body></html>");
|
||||
context.Response.ContentType = "text/html";
|
||||
|
|
@ -81,8 +81,8 @@ namespace StatusCodePagesSample
|
|||
var builder = new StringBuilder();
|
||||
builder.AppendLine("<html><body>");
|
||||
builder.AppendLine("<a href=\"" +
|
||||
HtmlEncoder.Default.HtmlEncode(context.Request.PathBase.ToString()) + "/missingpage/\">" +
|
||||
HtmlEncoder.Default.HtmlEncode(context.Request.PathBase.ToString()) + "/missingpage/</a><br>");
|
||||
HtmlEncoder.Default.Encode(context.Request.PathBase.ToString()) + "/missingpage/\">" +
|
||||
HtmlEncoder.Default.Encode(context.Request.PathBase.ToString()) + "/missingpage/</a><br>");
|
||||
|
||||
var space = string.Concat(Enumerable.Repeat(" ", 12));
|
||||
builder.AppendFormat("<br><b>{0}{1}{2}</b><br>", "Status Code", space, "Status Code Pages");
|
||||
|
|
|
|||
|
|
@ -31,6 +31,6 @@ namespace Microsoft.AspNet.Diagnostics.Elm
|
|||
|
||||
public QueryString Query { get; set; }
|
||||
|
||||
public IReadableStringCollection Cookies { get; set; }
|
||||
public IRequestCookieCollection Cookies { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
<!DOCTYPE html>
|
||||
|
|
|
|||
|
|
@ -27,13 +27,13 @@ namespace Microsoft.AspNet.Diagnostics.Views
|
|||
/// Parsed query data.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")]
|
||||
public IReadableStringCollection Query { get; set; }
|
||||
public IQueryCollection Query { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Request cookies.
|
||||
/// </summary>
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Model class contains collection")]
|
||||
public IReadableStringCollection Cookies { get; set; }
|
||||
public IRequestCookieCollection Cookies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Request headers.
|
||||
|
|
|
|||
|
|
@ -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
|
|||
/// <summary>
|
||||
/// Html encoder used to encode content.
|
||||
/// </summary>
|
||||
protected IHtmlEncoder HtmlEncoder { get; set; }
|
||||
protected HtmlEncoder HtmlEncoder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Url encoder used to encode content.
|
||||
/// </summary>
|
||||
protected IUrlEncoder UrlEncoder { get; set; }
|
||||
protected UrlEncoder UrlEncoder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// JavaScript encoder used to encode content.
|
||||
/// </summary>
|
||||
protected IJavaScriptStringEncoder JavaScriptStringEncoder { get; set; }
|
||||
protected JavaScriptEncoder JavaScriptEncoder { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
|||
/// <param name="value">The <see cref="string"/> to write.</param>
|
||||
protected void WriteTo(TextWriter writer, string value)
|
||||
{
|
||||
WriteLiteralTo(writer, HtmlEncoder.HtmlEncode(value));
|
||||
WriteLiteralTo(writer, HtmlEncoder.Encode(value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -308,7 +309,7 @@ namespace Microsoft.AspNet.Diagnostics.Views
|
|||
return string.Join("<br />" + Environment.NewLine,
|
||||
input.Split(new[] { "\r\n" }, StringSplitOptions.None)
|
||||
.SelectMany(s => s.Split(new[] { '\r', '\n' }, StringSplitOptions.None))
|
||||
.Select(HtmlEncoder.HtmlEncode));
|
||||
.Select(HtmlEncoder.Encode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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": {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -207,10 +207,10 @@ namespace Microsoft.AspNet.Diagnostics.Tests
|
|||
.Returns(new QueryString());
|
||||
contextMock
|
||||
.SetupGet(c => c.Request.Query)
|
||||
.Returns(new Mock<IReadableStringCollection>().Object);
|
||||
.Returns(new Mock<IQueryCollection>().Object);
|
||||
contextMock
|
||||
.SetupGet(c => c.Request.Cookies)
|
||||
.Returns(new Mock<IReadableStringCollection>().Object);
|
||||
.Returns(new Mock<IRequestCookieCollection>().Object);
|
||||
contextMock
|
||||
.Setup(c => c.Request.ReadFormAsync(It.IsAny<System.Threading.CancellationToken>()))
|
||||
.Returns(Task.FromResult(new Mock<IFormCollection>().Object));
|
||||
|
|
|
|||
|
|
@ -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<IHtmlEncoder>(new CustomHtmlEncoder()).
|
||||
AddInstance<HtmlEncoder>(new HtmlTestEncoder()).
|
||||
BuildServiceProvider());
|
||||
|
||||
// Act
|
||||
|
|
@ -213,29 +214,11 @@ namespace Microsoft.AspNet.Diagnostics.Tests
|
|||
// Assert
|
||||
string response = Encoding.UTF8.GetString(buffer);
|
||||
|
||||
Assert.True(response.Contains("<td>[LibInfo1]</td>"));
|
||||
Assert.True(response.Contains("<td>[1.0.0-beta1]</td>"));
|
||||
Assert.True(response.Contains("<td>[Path1]</td>"));
|
||||
Assert.True(response.Contains("<td>HtmlEncode[[LibInfo1]]</td>"));
|
||||
Assert.True(response.Contains("<td>HtmlEncode[[1.0.0-beta1]]</td>"));
|
||||
Assert.True(response.Contains("<td>HtmlEncode[[Path1]]</td>"));
|
||||
}
|
||||
}
|
||||
#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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue