Update `DefaultHtmlGenerator.GenerateAntiforgery()` to match latest `IAntiforgery.GetHtml()`
- #3123 (3 of 5 or so) - react to rest of aspnet/Antiforgery@6a9b38d - remove `HtmlEncoder` from localization requirements - literal `hidden` is no longer HTML encoded (was a no-op anyhow)
This commit is contained in:
parent
7bb0a1a4fe
commit
6e299d695f
|
|
@ -2,13 +2,10 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.Encodings.Web;
|
||||
using Microsoft.AspNet.Mvc.Razor;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.WebEncoders;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Localization.Internal
|
||||
{
|
||||
|
|
@ -28,10 +25,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal
|
|||
services.TryAdd(ServiceDescriptor.Singleton<IHtmlLocalizerFactory, HtmlLocalizerFactory>());
|
||||
services.TryAdd(ServiceDescriptor.Transient(typeof(IHtmlLocalizer<>), typeof(HtmlLocalizer<>)));
|
||||
services.TryAdd(ServiceDescriptor.Transient<IViewLocalizer, ViewLocalizer>());
|
||||
if (!services.Any(sd => sd.ServiceType == typeof(HtmlEncoder)))
|
||||
{
|
||||
services.TryAdd(ServiceDescriptor.Instance<HtmlEncoder>(HtmlEncoder.Default));
|
||||
}
|
||||
|
||||
services.AddLocalization(setupAction);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,8 +132,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
throw new ArgumentNullException(nameof(viewContext));
|
||||
}
|
||||
|
||||
var tag = _antiforgery.GetHtml(viewContext.HttpContext);
|
||||
return new HtmlString(tag);
|
||||
return _antiforgery.GetHtml(viewContext.HttpContext);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNet.Html.Abstractions;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
|
||||
|
|
@ -33,14 +32,17 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
|
|||
object htmlAttributes);
|
||||
|
||||
/// <summary>
|
||||
/// Genrate an <input type="hidden".../> element containing an antiforgery token.
|
||||
/// Generate an <input type="hidden".../> element containing an antiforgery token.
|
||||
/// </summary>
|
||||
/// <param name="viewContext">The <see cref="ViewContext"/> instance for the current scope.</param>
|
||||
/// <returns>An <see cref="IHtmlContent"/> instance for the <input type="hidden".../> element.</returns>
|
||||
/// <returns>
|
||||
/// An <see cref="IHtmlContent"/> instance for the <input type="hidden".../> element. Intended to be used
|
||||
/// inside a <form> element.
|
||||
/// </returns>
|
||||
IHtmlContent GenerateAntiforgery(ViewContext viewContext);
|
||||
|
||||
/// <summary>
|
||||
/// Generate a <input type="checkbox".../> element.
|
||||
/// Generate a <input type="checkbox".../> element.
|
||||
/// </summary>
|
||||
/// <param name="viewContext">The <see cref="ViewContext"/> instance for the current scope.</param>
|
||||
/// <param name="modelExplorer">The <see cref="ModelExplorer"/> for the model.</param>
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@
|
|||
"Microsoft.Extensions.PropertyHelper.Sources": {
|
||||
"version": "1.0.0-*",
|
||||
"type": "build"
|
||||
}
|
||||
},
|
||||
"Microsoft.Extensions.WebEncoders": "1.0.0-*"
|
||||
},
|
||||
"frameworks": {
|
||||
"net451": {},
|
||||
|
|
|
|||
|
|
@ -41,10 +41,9 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
|
|||
{
|
||||
if (input.Attribute("name") != null &&
|
||||
input.Attribute("type") != null &&
|
||||
(input.Attribute("name").Value == "__RequestVerificationToken" &&
|
||||
input.Attribute("type").Value == "hidden" ||
|
||||
input.Attribute("name").Value == "HtmlEncode[[__RequestVerificationToken]]" &&
|
||||
input.Attribute("type").Value == "HtmlEncode[[hidden]]"))
|
||||
input.Attribute("type").Value == "hidden" &&
|
||||
(input.Attribute("name").Value == "__RequestVerificationToken" ||
|
||||
input.Attribute("name").Value == "HtmlEncode[[__RequestVerificationToken]]"))
|
||||
{
|
||||
yield return input.Attributes("value").First().Value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,6 +78,6 @@
|
|||
</ul></div>
|
||||
<input type="HtmlEncode[[hidden]]" id="HtmlEncode[[Customer_Key]]" name="HtmlEncode[[Customer.Key]]" value="HtmlEncode[[KeyA]]" />
|
||||
<input type="submit" />
|
||||
<input name="HtmlEncode[[__RequestVerificationToken]]" type="HtmlEncode[[hidden]]" value="{0}" /><input name="HtmlEncode[[NeedSpecialHandle]]" type="HtmlEncode[[hidden]]" value="HtmlEncode[[false]]" /></form>
|
||||
<input name="HtmlEncode[[__RequestVerificationToken]]" type="hidden" value="{0}" /><input name="HtmlEncode[[NeedSpecialHandle]]" type="HtmlEncode[[hidden]]" value="HtmlEncode[[false]]" /></form>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -77,5 +77,5 @@
|
|||
</ul></div>
|
||||
<input id="HtmlEncode[[Customer_Key]]" name="HtmlEncode[[Customer.Key]]" type="HtmlEncode[[hidden]]" value="HtmlEncode[[KeyA]]" />
|
||||
<input type="submit"/>
|
||||
<input name="HtmlEncode[[__RequestVerificationToken]]" type="HtmlEncode[[hidden]]" value="{0}" /><input name="HtmlEncode[[NeedSpecialHandle]]" type="HtmlEncode[[hidden]]" value="HtmlEncode[[false]]" /></form></body>
|
||||
<input name="HtmlEncode[[__RequestVerificationToken]]" type="hidden" value="{0}" /><input name="HtmlEncode[[NeedSpecialHandle]]" type="HtmlEncode[[hidden]]" value="HtmlEncode[[false]]" /></form></body>
|
||||
</html>
|
||||
|
|
@ -55,11 +55,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal
|
|||
Assert.Equal(ServiceLifetime.Transient, service.Lifetime);
|
||||
},
|
||||
service =>
|
||||
{
|
||||
Assert.Equal(typeof(HtmlEncoder), service.ServiceType);
|
||||
Assert.Equal(ServiceLifetime.Singleton, service.Lifetime);
|
||||
},
|
||||
service =>
|
||||
{
|
||||
Assert.Equal(typeof(IStringLocalizerFactory), service.ServiceType);
|
||||
Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), service.ImplementationType);
|
||||
|
|
@ -197,11 +192,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal
|
|||
Assert.Equal(ServiceLifetime.Transient, service.Lifetime);
|
||||
},
|
||||
service =>
|
||||
{
|
||||
Assert.Equal(typeof(HtmlEncoder), service.ServiceType);
|
||||
Assert.Equal(ServiceLifetime.Singleton, service.Lifetime);
|
||||
},
|
||||
service =>
|
||||
{
|
||||
Assert.Equal(typeof(IStringLocalizerFactory), service.ServiceType);
|
||||
Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), service.ImplementationType);
|
||||
|
|
@ -276,11 +266,6 @@ namespace Microsoft.AspNet.Mvc.Localization.Internal
|
|||
Assert.Equal(ServiceLifetime.Transient, service.Lifetime);
|
||||
},
|
||||
service =>
|
||||
{
|
||||
Assert.Equal(typeof(HtmlEncoder), service.ServiceType);
|
||||
Assert.Equal(ServiceLifetime.Singleton, service.Lifetime);
|
||||
},
|
||||
service =>
|
||||
{
|
||||
Assert.Equal(typeof(IStringLocalizerFactory), service.ServiceType);
|
||||
Assert.Equal(typeof(ResourceManagerStringLocalizerFactory), service.ImplementationType);
|
||||
|
|
|
|||
Loading…
Reference in New Issue