From 2599e0f5cc00085bf3d97b0c52b080af0cea0233 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Mon, 11 Jun 2018 11:13:19 -0700 Subject: [PATCH] Fix up a few pieces for the fallback integrity check feature. - Regenerated test baselines. - Update code styling in TagHelpers. - Modified some comments for clarity. - Renamed fallback integrity attribute for both script and link tags. #7845 --- .../LinkTagHelper.cs | 15 +++++-------- .../ScriptTagHelper.cs | 18 +++++++-------- ...Site.HtmlGeneration_Home.Link.Encoded.html | 22 ++++++++++++++----- ...ationWebSite.HtmlGeneration_Home.Link.html | 22 ++++++++++++++----- .../RazorPagesWebSite.SimpleForms.html | 3 ++- .../LinkTagHelperTest.cs | 12 +++++----- .../ScriptTagHelperTest.cs | 8 +++---- .../Views/HtmlGeneration_Home/Link.cshtml | 10 ++++----- .../Views/HtmlGeneration_Home/Script.cshtml | 4 ++-- 9 files changed, 68 insertions(+), 46 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs index f54b613e9c..07054bed8a 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/LinkTagHelper.cs @@ -25,7 +25,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers [HtmlTargetElement("link", Attributes = HrefIncludeAttributeName, TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("link", Attributes = HrefExcludeAttributeName, TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("link", Attributes = FallbackHrefAttributeName, TagStructure = TagStructure.WithoutEndTag)] - [HtmlTargetElement("link", Attributes = FallbackHrefIntegrityCheckAttributeName, TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("link", Attributes = FallbackHrefIncludeAttributeName, TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("link", Attributes = FallbackHrefExcludeAttributeName, TagStructure = TagStructure.WithoutEndTag)] [HtmlTargetElement("link", Attributes = FallbackTestClassAttributeName, TagStructure = TagStructure.WithoutEndTag)] @@ -41,7 +40,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers private const string HrefIncludeAttributeName = "asp-href-include"; private const string HrefExcludeAttributeName = "asp-href-exclude"; private const string FallbackHrefAttributeName = "asp-fallback-href"; - private const string FallbackHrefIntegrityCheckAttributeName = "asp-fallback-href-integrity-check"; + private const string SuppressFallbackIntegrityAttributeName = "asp-suppress-fallback-integrity"; private const string FallbackHrefIncludeAttributeName = "asp-fallback-href-include"; private const string FallbackHrefExcludeAttributeName = "asp-fallback-href-exclude"; private const string FallbackTestClassAttributeName = "asp-fallback-test-class"; @@ -50,6 +49,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers private const string AppendVersionAttributeName = "asp-append-version"; private const string HrefAttributeName = "href"; private const string RelAttributeName = "rel"; + private const string IntegrityAttributeName = "integrity"; private static readonly Func Compare = (a, b) => a - b; private FileVersionProvider _fileVersionProvider; @@ -150,12 +150,10 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers public string FallbackHref { get; set; } /// - /// Boolean value that determines if Integrity Hash will be compared with value. - /// Value defaults to true if not provided. - /// Must be used in conjunction with . + /// Boolean value that determines if an integrity hash will be compared with value. /// - [HtmlAttributeName(FallbackHrefIntegrityCheckAttributeName)] - public bool? FallbackHrefIntegrityCheck { get; set; } + [HtmlAttributeName(SuppressFallbackIntegrityAttributeName)] + public bool SuppressFallbackIntegrity { get; set; } /// /// Value indicating if file version should be appended to the href urls. @@ -377,8 +375,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers continue; } - // do not write integrity attribute when FallbackHrefIntegrityCheck is false - if (attribute.Name.Equals("integrity", StringComparison.OrdinalIgnoreCase) && FallbackHrefIntegrityCheck == false) + if (SuppressFallbackIntegrity && string.Equals(attribute.Name, IntegrityAttributeName, StringComparison.OrdinalIgnoreCase)) { continue; } diff --git a/src/Microsoft.AspNetCore.Mvc.TagHelpers/ScriptTagHelper.cs b/src/Microsoft.AspNetCore.Mvc.TagHelpers/ScriptTagHelper.cs index b0e8289426..3d0ca2d33f 100644 --- a/src/Microsoft.AspNetCore.Mvc.TagHelpers/ScriptTagHelper.cs +++ b/src/Microsoft.AspNetCore.Mvc.TagHelpers/ScriptTagHelper.cs @@ -27,7 +27,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers [HtmlTargetElement("script", Attributes = FallbackSrcIncludeAttributeName)] [HtmlTargetElement("script", Attributes = FallbackSrcExcludeAttributeName)] [HtmlTargetElement("script", Attributes = FallbackTestExpressionAttributeName)] - [HtmlTargetElement("script", Attributes = FallbackIntegrityCheckAttributeName)] [HtmlTargetElement("script", Attributes = AppendVersionAttributeName)] public class ScriptTagHelper : UrlResolutionTagHelper { @@ -35,10 +34,11 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers private const string SrcExcludeAttributeName = "asp-src-exclude"; private const string FallbackSrcAttributeName = "asp-fallback-src"; private const string FallbackSrcIncludeAttributeName = "asp-fallback-src-include"; - private const string FallbackIntegrityCheckAttributeName = "asp-fallback-integrity-check"; + private const string SuppressFallbackIntegrityAttributeName = "asp-suppress-fallback-integrity"; private const string FallbackSrcExcludeAttributeName = "asp-fallback-src-exclude"; private const string FallbackTestExpressionAttributeName = "asp-fallback-test"; private const string SrcAttributeName = "src"; + private const string IntegrityAttributeName = "integrity"; private const string AppendVersionAttributeName = "asp-append-version"; private static readonly Func Compare = (a, b) => a - b; private FileVersionProvider _fileVersionProvider; @@ -132,12 +132,10 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers public string FallbackSrc { get; set; } /// - /// Boolean value that determines if Integrity Hash will be compared with value. - /// Value defaults to true if not provided. - /// Must be used in conjunction with . + /// Boolean value that determines if an integrity hash will be compared with value. /// - [HtmlAttributeName(FallbackIntegrityCheckAttributeName)] - public bool? FallbackIntegrityCheck { get; set; } + [HtmlAttributeName(SuppressFallbackIntegrityAttributeName)] + public bool SuppressFallbackIntegrity { get; set; } /// /// Value indicating if file version should be appended to src urls. @@ -322,8 +320,10 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers var attribute = attributes[i]; if (!attribute.Name.Equals(SrcAttributeName, StringComparison.OrdinalIgnoreCase)) { - // do not write integrity attribute when fallbackintegrityCheck is false - if (attribute.Name.Equals("integrity", StringComparison.OrdinalIgnoreCase) && FallbackIntegrityCheck == false) continue; + if (SuppressFallbackIntegrity && string.Equals(IntegrityAttributeName, attribute.Name, StringComparison.OrdinalIgnoreCase)) + { + continue; + } StringWriter.Write(' '); attribute.WriteTo(StringWriter, HtmlEncoder); diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Link.Encoded.html b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Link.Encoded.html index 30f65f5ccd..0e28eac841 100644 --- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Link.Encoded.html +++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Link.Encoded.html @@ -11,10 +11,10 @@ - + - + @@ -41,6 +41,18 @@ + + + + + + + + + + + + @@ -81,7 +93,7 @@ - + @@ -101,7 +113,7 @@ - + @@ -129,7 +141,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Link.html b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Link.html index cb7acce37c..ffa6be6fdf 100644 --- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Link.html +++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Link.html @@ -11,10 +11,10 @@ - + - + @@ -41,6 +41,18 @@ + + + + + + + + + + + + @@ -82,7 +94,7 @@ - + @@ -102,7 +114,7 @@ - + @@ -130,7 +142,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/RazorPagesWebSite.SimpleForms.html b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/RazorPagesWebSite.SimpleForms.html index 27ca37082a..ef06135e61 100644 --- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/RazorPagesWebSite.SimpleForms.html +++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/compiler/resources/RazorPagesWebSite.SimpleForms.html @@ -3,4 +3,5 @@
-
\ No newline at end of file +
+
\ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/LinkTagHelperTest.cs b/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/LinkTagHelperTest.cs index 4fa536e096..833da15fc4 100644 --- a/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/LinkTagHelperTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/LinkTagHelperTest.cs @@ -264,7 +264,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers tagHelper.AppendVersion = true; } }, - // asp-fallback-href-integrity-check Attribute true + // asp-suppress-fallback-integrity Attribute true { new TagHelperAttributeList { @@ -273,7 +273,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers new TagHelperAttribute("asp-fallback-test-property", "visibility"), new TagHelperAttribute("asp-fallback-test-value", "hidden"), new TagHelperAttribute("asp-append-version", "true"), - new TagHelperAttribute("asp-fallback-href-integrity-check", "true") + new TagHelperAttribute("asp-suppress-fallback-integrity", "true") }, tagHelper => { @@ -282,10 +282,10 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers tagHelper.FallbackTestProperty = "visibility"; tagHelper.FallbackTestValue = "hidden"; tagHelper.AppendVersion = true; - tagHelper.FallbackHrefIntegrityCheck = true; + tagHelper.SuppressFallbackIntegrity = true; } }, - // asp-fallback-href-integrity-check Attribute false + // asp-suppress-fallback-integrity Attribute false { new TagHelperAttributeList { @@ -294,7 +294,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers new TagHelperAttribute("asp-fallback-test-property", "visibility"), new TagHelperAttribute("asp-fallback-test-value", "hidden"), new TagHelperAttribute("asp-append-version", "true"), - new TagHelperAttribute("asp-fallback-href-integrity-check", "false") + new TagHelperAttribute("asp-suppress-fallback-integrity", "false") }, tagHelper => { @@ -303,7 +303,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers tagHelper.FallbackTestProperty = "visibility"; tagHelper.FallbackTestValue = "hidden"; tagHelper.AppendVersion = true; - tagHelper.FallbackHrefIntegrityCheck = false; + tagHelper.SuppressFallbackIntegrity = false; } }, }; diff --git a/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/ScriptTagHelperTest.cs b/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/ScriptTagHelperTest.cs index a30ee40535..923a76b889 100644 --- a/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/ScriptTagHelperTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/ScriptTagHelperTest.cs @@ -161,13 +161,13 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers { new TagHelperAttribute("asp-fallback-src", "test.js"), new TagHelperAttribute("asp-fallback-test", "isavailable()"), - new TagHelperAttribute("asp-fallback-integrity-check", "false") + new TagHelperAttribute("asp-suppress-fallback-integrity", "false") }, tagHelper => { tagHelper.FallbackSrc = "test.js"; tagHelper.FallbackTestExpression = "isavailable()"; - tagHelper.FallbackIntegrityCheck = false; + tagHelper.SuppressFallbackIntegrity = false; } }, { @@ -202,14 +202,14 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers new TagHelperAttribute("asp-fallback-src", "test.js"), new TagHelperAttribute("asp-fallback-src-include", "*.js"), new TagHelperAttribute("asp-fallback-test", "isavailable()"), - new TagHelperAttribute("asp-fallback-integrity-check", "false") + new TagHelperAttribute("asp-suppress-fallback-integrity", "false") }, tagHelper => { tagHelper.FallbackSrc = "test.js"; tagHelper.FallbackSrcInclude = "*.css"; tagHelper.FallbackTestExpression = "isavailable()"; - tagHelper.FallbackIntegrityCheck = false; + tagHelper.SuppressFallbackIntegrity = false; } }, { diff --git a/test/WebSites/HtmlGenerationWebSite/Views/HtmlGeneration_Home/Link.cshtml b/test/WebSites/HtmlGenerationWebSite/Views/HtmlGeneration_Home/Link.cshtml index 26acbf3b51..ffa657373f 100644 --- a/test/WebSites/HtmlGenerationWebSite/Views/HtmlGeneration_Home/Link.cshtml +++ b/test/WebSites/HtmlGenerationWebSite/Views/HtmlGeneration_Home/Link.cshtml @@ -46,7 +46,7 @@ asp-fallback-test-property="visibility" asp-fallback-test-value="hidden" /> - + - + + asp-suppress-fallback-integrity="false" /> - + + asp-suppress-fallback-integrity /> @@ -44,7 +44,7 @@