diff --git a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs index 881a94e85b..5262f864fc 100644 --- a/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs +++ b/src/Microsoft.AspNet.Mvc.Razor.Host/MvcRazorHost.cs @@ -3,7 +3,9 @@ using System.Collections.Generic; using System.IO; +#if NET45 using Microsoft.AspNet.FileProviders; +#endif using Microsoft.AspNet.Mvc.Razor.Directives; using Microsoft.AspNet.Mvc.Razor.Internal; using Microsoft.AspNet.Razor; @@ -18,6 +20,8 @@ namespace Microsoft.AspNet.Mvc.Razor public class MvcRazorHost : RazorEngineHost, IMvcRazorHost { private const string BaseType = "Microsoft.AspNet.Mvc.Razor.RazorPage"; + private const string HtmlHelperPropertyName = "Html"; + private static readonly string[] _defaultNamespaces = new[] { "System", @@ -28,7 +32,7 @@ namespace Microsoft.AspNet.Mvc.Razor }; private static readonly Chunk[] _defaultInheritedChunks = new[] { - new InjectChunk("Microsoft.AspNet.Mvc.Rendering.IHtmlHelper", "Html"), + new InjectChunk("Microsoft.AspNet.Mvc.Rendering.IHtmlHelper", HtmlHelperPropertyName), new InjectChunk("Microsoft.AspNet.Mvc.IViewComponentHelper", "Component"), new InjectChunk("Microsoft.AspNet.Mvc.IUrlHelper", "Url"), }; @@ -76,6 +80,8 @@ namespace Microsoft.AspNet.Mvc.Razor ScopeManagerBeginMethodName = nameof(TagHelperScopeManager.Begin), ScopeManagerEndMethodName = nameof(TagHelperScopeManager.End), + TagHelperContentTypeName = nameof(TagHelperContent), + // Can't use nameof because RazorPage is not accessible here. CreateTagHelperMethodName = "CreateTagHelper", StartTagHelperWritingScopeMethodName = "StartTagHelperWritingScope", @@ -83,6 +89,9 @@ namespace Microsoft.AspNet.Mvc.Razor WriteTagHelperAsyncMethodName = "WriteTagHelperAsync", WriteTagHelperToAsyncMethodName = "WriteTagHelperToAsync", + + // Can't use nameof because IHtmlHelper is (also) not accessible here. + MarkAsHtmlEncodedMethodName = HtmlHelperPropertyName + ".Raw", }) { ResolveUrlMethodName = "Href", diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorPage.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorPage.cs index a9ad88ad98..37c82d949f 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/RazorPage.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/RazorPage.cs @@ -286,11 +286,10 @@ namespace Microsoft.AspNet.Mvc.Razor foreach (var attribute in tagHelperOutput.Attributes) { - var value = HtmlEncoder.HtmlEncode(attribute.Value); writer.Write(' '); writer.Write(attribute.Key); writer.Write("=\""); - writer.Write(value); + WriteTo(writer, HtmlEncoder, attribute.Value, escapeQuotes: true); writer.Write('"'); } @@ -358,26 +357,67 @@ namespace Microsoft.AspNet.Mvc.Razor /// public virtual void WriteTo([NotNull] TextWriter writer, object value) { - if (value != null && value != HtmlString.Empty) + WriteTo(writer, HtmlEncoder, value, escapeQuotes: false); + } + + /// + /// Writes the specified with HTML encoding to given . + /// + /// The instance to write to. + /// The to use when encoding . + /// The to write. + /// + /// If true escapes double quotes in a of type . + /// Otherwise writes values as-is. + /// + /// + /// s of type are written without encoding and the + /// is invoked for types. + /// For all other types, the encoded result of is written to the + /// . + /// + public static void WriteTo( + [NotNull] TextWriter writer, + [NotNull] IHtmlEncoder encoder, + object value, + bool escapeQuotes) + { + if (value == null || value == HtmlString.Empty) { - var helperResult = value as HelperResult; - if (helperResult != null) - { - helperResult.WriteTo(writer); - } - else - { - var htmlString = value as HtmlString; - if (htmlString != null) - { - writer.Write(htmlString); - } - else - { - WriteTo(writer, value.ToString()); - } - } + return; } + + var helperResult = value as HelperResult; + if (helperResult != null) + { + helperResult.WriteTo(writer); + return; + } + + var htmlString = value as HtmlString; + if (htmlString != null) + { + if (escapeQuotes) + { + // In this case the text likely came directly from the Razor source. Since the original string is + // an attribute value that may have been quoted with single quotes, must handle any double quotes + // in the value. Writing the value out surrounded by double quotes. + // + // Do not combine following condition with check of escapeQuotes; htmlString.ToString() can be + // expensive when the HtmlString is created with a StringCollectionTextWriter. + var stringValue = htmlString.ToString(); + if (stringValue.Contains("\"")) + { + writer.Write(stringValue.Replace("\"", """)); + return; + } + } + + htmlString.WriteTo(writer); + return; + } + + WriteTo(writer, encoder, value.ToString()); } /// @@ -386,10 +426,15 @@ namespace Microsoft.AspNet.Mvc.Razor /// The instance to write to. /// The to write. public virtual void WriteTo([NotNull] TextWriter writer, string value) + { + WriteTo(writer, HtmlEncoder, value); + } + + private static void WriteTo(TextWriter writer, IHtmlEncoder encoder, string value) { if (!string.IsNullOrEmpty(value)) { - HtmlEncoder.HtmlEncode(value, writer); + encoder.HtmlEncode(value, writer); } } @@ -772,33 +817,5 @@ namespace Microsoft.AspNet.Mvc.Razor throw new InvalidOperationException(Resources.FormatRazorPage_MethodCannotBeCalled(methodName)); } } - - private class TagHelperContentWrapperTextWriter : TextWriter - { - public TagHelperContentWrapperTextWriter(Encoding encoding) - { - Content = new DefaultTagHelperContent(); - Encoding = encoding; - } - - public TagHelperContent Content { get; } - - public override Encoding Encoding { get; } - - public override void Write(string value) - { - Content.Append(value); - } - - public override void Write(char value) - { - Content.Append(value.ToString()); - } - - public override string ToString() - { - return Content.ToString(); - } - } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.Razor/TagHelperContentWrapperTextWriter.cs b/src/Microsoft.AspNet.Mvc.Razor/TagHelperContentWrapperTextWriter.cs new file mode 100644 index 0000000000..cf59592127 --- /dev/null +++ b/src/Microsoft.AspNet.Mvc.Razor/TagHelperContentWrapperTextWriter.cs @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; +using System.Text; +using Microsoft.AspNet.Razor.Runtime.TagHelpers; +using Microsoft.Framework.Internal; + +namespace Microsoft.AspNet.Mvc.Razor +{ + /// + /// implementation which writes to a instance. + /// + public class TagHelperContentWrapperTextWriter : TextWriter + { + /// + /// Initializes a new instance of the class. + /// + /// The in which output is written. + public TagHelperContentWrapperTextWriter([NotNull] Encoding encoding) + : this(encoding, new DefaultTagHelperContent()) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The in which output is written. + /// The to write to. + public TagHelperContentWrapperTextWriter([NotNull] Encoding encoding, [NotNull] TagHelperContent content) + { + Content = content; + Encoding = encoding; + } + + /// + /// The this writes to. + /// + public TagHelperContent Content { get; } + + /// + public override Encoding Encoding { get; } + + /// + public override void Write(string value) + { + Content.Append(value); + } + + /// + public override void Write(char value) + { + Content.Append(value.ToString()); + } + + /// + public override string ToString() + { + return Content.ToString(); + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/AnchorTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/AnchorTagHelper.cs index 0f356bcc20..5907872fe6 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/AnchorTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/AnchorTagHelper.cs @@ -153,7 +153,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // TODO: https://github.com/aspnet/Razor/issues/89 - We will not need this method once #89 is completed. private static Dictionary GetRouteValues( - TagHelperOutput output, IEnumerable> routePrefixedAttributes) + TagHelperOutput output, + IEnumerable> routePrefixedAttributes) { Dictionary routeValues = null; if (routePrefixedAttributes.Any()) @@ -161,10 +162,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Prefixed values should be treated as bound attributes, remove them from the output. output.RemoveRange(routePrefixedAttributes); - // Generator.GenerateForm does not accept a Dictionary for route values. + // Remove prefix from keys and convert all values to strings. HtmlString and similar classes are not + // meaningful to routing. routeValues = routePrefixedAttributes.ToDictionary( attribute => attribute.Key.Substring(RouteAttributePrefix.Length), - attribute => (object)attribute.Value); + attribute => (object)attribute.Value.ToString()); } return routeValues; diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/FormTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/FormTagHelper.cs index 4b24ecb609..1a241046b0 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/FormTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/FormTagHelper.cs @@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Protected to ensure subclasses are correctly activated. Internal for ease of use when testing. [Activate] protected internal IHtmlGenerator Generator { get; set; } - + /// /// The name of the action method. /// @@ -41,12 +41,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers public string Controller { get; set; } /// - /// The HTTP method for processing the form, either GET or POST. - /// - public string Method { get; set; } - - /// - /// Whether the anti-forgery token should be generated. + /// Whether the anti-forgery token should be generated. /// /// Defaults to false if user provides an action attribute; true otherwise. [HtmlAttributeName(AntiForgeryAttributeName)] @@ -84,12 +79,6 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // User is using the FormTagHelper like a normal
tag. Anti-forgery default should be false to // not force the anti-forgery token on the user. antiForgeryDefault = false; - - // Restore method attribute. - if (Method != null) - { - output.CopyHtmlAttribute(nameof(Method), context); - } } else { @@ -98,7 +87,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers Action, Controller, routeValues, - Method, + method: null, htmlAttributes: null); if (tagBuilder != null) @@ -120,7 +109,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // TODO: https://github.com/aspnet/Razor/issues/89 - We will not need this method once #89 is completed. private static Dictionary GetRouteValues( - TagHelperOutput output, IEnumerable> routePrefixedAttributes) + TagHelperOutput output, + IEnumerable> routePrefixedAttributes) { Dictionary routeValues = null; if (routePrefixedAttributes.Any()) @@ -128,10 +118,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Prefixed values should be treated as bound attributes, remove them from the output. output.RemoveRange(routePrefixedAttributes); - // Generator.GenerateForm does not accept a Dictionary for route values. + // Remove prefix from keys and convert all values to strings. HtmlString and similar classes are not + // meaningful to routing. routeValues = routePrefixedAttributes.ToDictionary( attribute => attribute.Key.Substring(RouteAttributePrefix.Length), - attribute => (object)attribute.Value); + attribute => (object)attribute.Value.ToString()); } return routeValues; diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs index 08c30ac708..78818cb5dc 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/InputTagHelper.cs @@ -8,7 +8,6 @@ using System.Linq; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Razor.Runtime.TagHelpers; -using Microsoft.AspNet.Razor.TagHelpers; namespace Microsoft.AspNet.Mvc.TagHelpers { @@ -112,7 +111,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers { // Pass through attributes that are also well-known HTML attributes. Must be done prior to any copying // from a TagBuilder. - if (!string.IsNullOrEmpty(InputTypeName)) + if (InputTypeName != null) { output.CopyHtmlAttribute("type", context); } diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs index 1bf94f9e9d..28a6d65640 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Globalization; using System.Linq; using Microsoft.AspNet.Hosting; @@ -10,7 +11,6 @@ using Microsoft.AspNet.Mvc.TagHelpers.Internal; using Microsoft.AspNet.Razor.Runtime.TagHelpers; using Microsoft.Framework.Caching.Memory; using Microsoft.Framework.Logging; -using Microsoft.Framework.Runtime; using Microsoft.Framework.WebEncoders; namespace Microsoft.AspNet.Mvc.TagHelpers @@ -98,6 +98,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers Fallback = 2, } + /// + /// Address of the linked resource. + /// + /// + /// Passed through to the generated HTML in all cases. + /// + [HtmlAttributeName(HrefAttributeName)] + public string Href { get; set; } + /// /// A comma separated list of globbed file patterns of CSS stylesheets to load. /// The glob patterns are assessed relative to the application's 'webroot' setting. @@ -189,12 +198,21 @@ namespace Microsoft.AspNet.Mvc.TagHelpers [Activate] protected internal IHtmlEncoder HtmlEncoder { get; set; } + [Activate] + protected internal IJavaScriptStringEncoder JavaScriptEncoder { get; set; } + // Internal for ease of use when testing. protected internal GlobbingUrlBuilder GlobbingUrlBuilder { get; set; } /// public override void Process(TagHelperContext context, TagHelperOutput output) { + // Pass through attribute that is also a well-known HTML attribute. + if (Href != null) + { + output.CopyHtmlAttribute(HrefAttributeName, context); + } + var modeResult = AttributeMatcher.DetermineMode(context, ModeDetails); var logger = Logger ?? LoggerFactory.CreateLogger(); @@ -210,8 +228,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Get the highest matched mode var mode = modeResult.FullMatches.Select(match => match.Mode).Max(); - // NOTE: Values in TagHelperOutput.Attributes are already HtmlEncoded - var attributes = new Dictionary(output.Attributes); + // NOTE: Values in TagHelperOutput.Attributes may already be HTML-encoded. + var attributes = new Dictionary(output.Attributes); var builder = new DefaultTagHelperContent(); @@ -236,17 +254,17 @@ namespace Microsoft.AspNet.Mvc.TagHelpers output.Content.SetContent(builder); } - private void BuildGlobbedLinkTags(IDictionary attributes, TagHelperContent builder) + private void BuildGlobbedLinkTags(IDictionary attributes, TagHelperContent builder) { - // Build a tag for each matched href as well as the original one in the source file - string staticHref; - attributes.TryGetValue(HrefAttributeName, out staticHref); - EnsureGlobbingUrlBuilder(); - var urls = GlobbingUrlBuilder.BuildUrlList(staticHref, HrefInclude, HrefExclude); + // Build a tag for each matched href as well as the original one in the source file + var urls = GlobbingUrlBuilder.BuildUrlList(Href, HrefInclude, HrefExclude); foreach (var url in urls) { + // "url" values come from bound attributes and globbing. Must always be non-null. + Debug.Assert(url != null); + attributes[HrefAttributeName] = url; BuildLinkTag(attributes, builder); } @@ -260,10 +278,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers if (fallbackHrefs.Length > 0) { - if (ShouldAddFileVersion()) + if (FileVersion == true) { for (var i=0; i < fallbackHrefs.Length; i++) { + // fallbackHrefs come from bound attributes and globbing. Must always be non-null. + Debug.Assert(fallbackHrefs[i] != null); + fallbackHrefs[i] = _fileVersionProvider.AddFileVersionToPath(fallbackHrefs[i]); } } @@ -279,13 +300,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Build the "); + builder + .Append(""); } } @@ -311,7 +334,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers } } - private void BuildLinkTag(IDictionary attributes, TagHelperContent builder) + private void BuildLinkTag(IDictionary attributes, TagHelperContent builder) { EnsureFileVersionProvider(); builder.Append(""); } - - private bool ShouldAddFileVersion() - { - return FileVersion ?? false; - } } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/OptionTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/OptionTagHelper.cs index 10529cc6e8..e55ed3761c 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/OptionTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/OptionTagHelper.cs @@ -6,7 +6,6 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Razor.Runtime.TagHelpers; -using Microsoft.AspNet.Razor.TagHelpers; namespace Microsoft.AspNet.Mvc.TagHelpers { @@ -28,14 +27,6 @@ namespace Microsoft.AspNet.Mvc.TagHelpers [Activate] protected internal ViewContext ViewContext { get; set; } - /// - /// Specifies that this <option> is pre-selected. - /// - /// - /// Passed through to the generated HTML in all cases. - /// - public string Selected { get; set; } - /// /// Specifies a value for the <option> element. /// @@ -59,12 +50,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers output.CopyHtmlAttribute(nameof(Value), context); } - if (Selected != null) - { - // This + + diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Index.Encoded.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Index.Encoded.html new file mode 100644 index 0000000000..9dcc236745 --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Index.Encoded.html @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Index.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Index.html index a40ea80fa0..9cf4efaad1 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Index.html +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Index.html @@ -4,10 +4,10 @@
MvcTagHelperTest Index diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Link.Encoded.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Link.Encoded.html new file mode 100644 index 0000000000..b2c0357ffe --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Link.Encoded.html @@ -0,0 +1,131 @@ + + + + + + Link + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Link Tag Helper Test

+ + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Link.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Link.html index be221d21d0..95d54317d0 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Link.html +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Link.html @@ -7,19 +7,19 @@ Link - + - + - + - + @@ -31,14 +31,14 @@ - + - + - - + + @@ -49,11 +49,11 @@ - + - + @@ -61,19 +61,19 @@ - + - + - + - + @@ -85,44 +85,44 @@ - + - + - + - + - + - + - + - + - + - + - + diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Order.Encoded.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Order.Encoded.html new file mode 100644 index 0000000000..c1fb5671a9 --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Order.Encoded.html @@ -0,0 +1,85 @@ + + + + + + + + + +
+
+ + +
+
+ + +
+
+ + + +
+
+ + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + +
+
+ + +
+
+ + + +
+
+ + +
+
+ + + +
+
+ + Male + Female + +
+
  • +
+ + +
+ + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.OrderUsingHtmlHelpers.Encoded.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.OrderUsingHtmlHelpers.Encoded.html new file mode 100644 index 0000000000..5f5fd01a46 --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.OrderUsingHtmlHelpers.Encoded.html @@ -0,0 +1,84 @@ + + + + + + + + + +
+
+ + +
+
+ + +
+
+ + + +
+
+ + + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + +
+
+ + +
+
+ + + +
+
+ + +
+
+ + + +
+
+ + Male + Female + +
+
  • +
+ + +
+ + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Product.Encoded.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Product.Encoded.html new file mode 100644 index 0000000000..6356668cc9 --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Product.Encoded.html @@ -0,0 +1,23 @@ + + + + + + + + + +
+
+ + +
+
+ + +
+ +
+ + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Script.Encoded.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Script.Encoded.html new file mode 100644 index 0000000000..90239290b1 --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Script.Encoded.html @@ -0,0 +1,116 @@ + + + + + + Script + + +

Script tag helper test

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Script.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Script.html index 1aa41653c6..dfa9051e3c 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Script.html +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/MvcTagHelpersWebSite.MvcTagHelper_Home.Script.html @@ -7,34 +7,34 @@

Script tag helper test

- - - + - - + - + - + - + - + - + - + - + \r\n\r\n", output.Content.GetContent()); } @@ -679,10 +675,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers ["asp-src-include"] = "*.js", ["asp-file-version"] = "true" }); - var output = MakeTagHelperOutput("script", attributes: new Dictionary - { - ["src"] = "/js/site.js" - }); + var output = MakeTagHelperOutput("script", attributes: new Dictionary()); var logger = new Mock>(); var hostingEnvironment = MakeHostingEnvironment(); var viewContext = MakeViewContext(); @@ -698,6 +691,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers SrcInclude = "*.js", FileVersion = true, HtmlEncoder = new TestHtmlEncoder(), + JavaScriptEncoder = new TestJavaScriptEncoder(), + Src = "/js/site.js", Cache = MakeCache(), }; @@ -748,9 +743,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers return viewContext; } - private TagHelperOutput MakeTagHelperOutput(string tagName, IDictionary attributes = null) + private TagHelperOutput MakeTagHelperOutput(string tagName, IDictionary attributes = null) { - attributes = attributes ?? new Dictionary(); + attributes = attributes ?? new Dictionary(); return new TagHelperOutput(tagName, attributes); } @@ -817,27 +812,5 @@ namespace Microsoft.AspNet.Mvc.TagHelpers }); return cache.Object; } - - private class TestHtmlEncoder : IHtmlEncoder - { - public string HtmlEncode(string value) - { - return "HtmlEncode[[" + value + "]]"; - } - - public void HtmlEncode(string value, int startIndex, int charCount, TextWriter output) - { - output.Write("HtmlEncode[["); - output.Write(value.Substring(startIndex, charCount)); - output.Write("]]"); - } - - public void HtmlEncode(char[] value, int startIndex, int charCount, TextWriter output) - { - output.Write("HtmlEncode[["); - output.Write(value, startIndex, charCount); - output.Write("]]"); - } - } } } \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/SelectTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/SelectTagHelperTest.cs index edcc515f3d..fb21004ba7 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/SelectTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/SelectTagHelperTest.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Razor.Runtime.TagHelpers; -using Microsoft.Framework.WebEncoders; using Moq; using Xunit; @@ -172,13 +171,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers string ignored) { // Arrange - var originalAttributes = new Dictionary + var originalAttributes = new Dictionary { { "class", "form-control" }, }; var originalPostContent = "original content"; - var expectedAttributes = new Dictionary(originalAttributes) + var expectedAttributes = new Dictionary(originalAttributes) { { "id", nameAndId.Id }, { "name", nameAndId.Name }, @@ -258,13 +257,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers string expectedOptions) { // Arrange - var originalAttributes = new Dictionary + var originalAttributes = new Dictionary { { "class", "form-control" }, }; var originalPostContent = "original content"; - var expectedAttributes = new Dictionary(originalAttributes) + var expectedAttributes = new Dictionary(originalAttributes) { { "id", nameAndId.Id }, { "name", nameAndId.Name }, @@ -359,13 +358,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers string expectedOptions) { // Arrange - var originalAttributes = new Dictionary + var originalAttributes = new Dictionary { { "class", "form-control" }, }; var originalPostContent = "original content"; - var expectedAttributes = new Dictionary(originalAttributes) + var expectedAttributes = new Dictionary(originalAttributes) { { "id", nameAndId.Id }, { "name", nameAndId.Name }, @@ -465,7 +464,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Provided for completeness. Select tag helper does not confirm AllAttributes set is consistent. { attributeName, attributeValue }, }; - var originalAttributes = new Dictionary + var originalAttributes = new Dictionary { { attributeName, attributeValue }, }; @@ -547,7 +546,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers { // Arrange var contextAttributes = new Dictionary(); - var originalAttributes = new Dictionary(); + var originalAttributes = new Dictionary(); var propertyName = "Property1"; var tagName = "select"; diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TagHelperOutputExtensionsTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TagHelperOutputExtensionsTest.cs index 7a8e8bfa70..43cef4b14a 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TagHelperOutputExtensionsTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TagHelperOutputExtensionsTest.cs @@ -21,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Arrange var tagHelperOutput = new TagHelperOutput( "p", - attributes: new Dictionary()); + attributes: new Dictionary()); var tagHelperContext = new TagHelperContext( allAttributes: new Dictionary(StringComparer.Ordinal) { @@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers tagHelperContent.Append("Something"); return Task.FromResult(tagHelperContent); }); - var expectedAttribute = new KeyValuePair(attributeName, attributeValue); + var expectedAttribute = new KeyValuePair(attributeName, attributeValue); // Act tagHelperOutput.CopyHtmlAttribute("hello", tagHelperContext); @@ -52,11 +52,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var attributeName = "hello"; var tagHelperOutput = new TagHelperOutput( "p", - attributes: new Dictionary() + attributes: new Dictionary() { { attributeName, "world2" } }); - var expectedAttribute = new KeyValuePair(attributeName, "world2"); + var expectedAttribute = new KeyValuePair(attributeName, "world2"); var tagHelperContext = new TagHelperContext( allAttributes: new Dictionary(StringComparer.Ordinal) { @@ -85,12 +85,12 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Arrange var tagHelperOutput = new TagHelperOutput( "p", - attributes: new Dictionary() + attributes: new Dictionary() { { "route-Hello", "World" }, { "Route-I", "Am" } }); - var expectedAttribute = new KeyValuePair("type", "btn"); + var expectedAttribute = new KeyValuePair("type", "btn"); tagHelperOutput.Attributes.Add(expectedAttribute); var attributes = tagHelperOutput.FindPrefixedAttributes("route-"); @@ -108,7 +108,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Arrange var tagHelperOutput = new TagHelperOutput( "p", - attributes: new Dictionary() + attributes: new Dictionary() { { "routeHello", "World" }, { "Routee-I", "Am" } @@ -131,8 +131,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Arrange var tagHelperOutput = new TagHelperOutput( "p", - attributes: new Dictionary()); - var expectedAttribute = new KeyValuePair("type", "btn"); + attributes: new Dictionary()); + var expectedAttribute = new KeyValuePair("type", "btn"); tagHelperOutput.Attributes.Add(expectedAttribute); var tagBuilder = new TagBuilder("p", new HtmlEncoder()); @@ -152,13 +152,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Arrange var tagHelperOutput = new TagHelperOutput( "p", - attributes: new Dictionary()); + attributes: new Dictionary()); tagHelperOutput.Attributes.Add("class", "Hello"); var tagBuilder = new TagBuilder("p", new HtmlEncoder()); tagBuilder.Attributes.Add("class", "btn"); - var expectedAttribute = new KeyValuePair("class", "Hello btn"); + var expectedAttribute = new KeyValuePair("class", "Hello btn"); // Act tagHelperOutput.MergeAttributes(tagBuilder); @@ -178,7 +178,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Arrange var tagHelperOutput = new TagHelperOutput( "p", - attributes: new Dictionary()); + attributes: new Dictionary()); tagHelperOutput.Attributes.Add(originalName, "Hello"); var tagBuilder = new TagBuilder("p", new HtmlEncoder()); @@ -189,7 +189,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Assert var attribute = Assert.Single(tagHelperOutput.Attributes); - Assert.Equal(new KeyValuePair(originalName, "Hello btn"), attribute); + Assert.Equal(new KeyValuePair(originalName, "Hello btn"), attribute); } [Fact] @@ -198,11 +198,11 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Arrange var tagHelperOutput = new TagHelperOutput( "p", - attributes: new Dictionary()); + attributes: new Dictionary()); var tagBuilder = new TagBuilder("p", new HtmlEncoder()); - var expectedAttribute = new KeyValuePair("visible", "val < 3"); - tagBuilder.Attributes.Add(expectedAttribute); + var expectedAttribute = new KeyValuePair("visible", "val < 3"); + tagBuilder.Attributes.Add("visible", "val < 3"); // Act tagHelperOutput.MergeAttributes(tagBuilder); @@ -218,13 +218,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Arrange var tagHelperOutput = new TagHelperOutput( "p", - attributes: new Dictionary()); + attributes: new Dictionary()); var tagBuilder = new TagBuilder("p", new HtmlEncoder()); - var expectedAttribute1 = new KeyValuePair("class", "btn"); - var expectedAttribute2 = new KeyValuePair("class2", "btn"); - tagBuilder.Attributes.Add(expectedAttribute1); - tagBuilder.Attributes.Add(expectedAttribute2); + var expectedAttribute1 = new KeyValuePair("class", "btn"); + var expectedAttribute2 = new KeyValuePair("class2", "btn"); + tagBuilder.Attributes.Add("class", "btn"); + tagBuilder.Attributes.Add("class2", "btn"); // Act tagHelperOutput.MergeAttributes(tagBuilder); @@ -243,8 +243,8 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Arrange var tagHelperOutput = new TagHelperOutput( "p", - attributes: new Dictionary()); - var expectedAttribute = new KeyValuePair("class", "btn"); + attributes: new Dictionary()); + var expectedAttribute = new KeyValuePair("class", "btn"); tagHelperOutput.Attributes.Add(expectedAttribute); var tagBuilder = new TagBuilder("p", new HtmlEncoder()); @@ -263,13 +263,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers // Arrange var tagHelperOutput = new TagHelperOutput( "p", - attributes: new Dictionary()); - var expectedOutputAttribute = new KeyValuePair("class", "btn"); + attributes: new Dictionary()); + var expectedOutputAttribute = new KeyValuePair("class", "btn"); tagHelperOutput.Attributes.Add(expectedOutputAttribute); var tagBuilder = new TagBuilder("p", new HtmlEncoder()); - var expectedBuilderAttribute = new KeyValuePair("for", "hello"); - tagBuilder.Attributes.Add(expectedBuilderAttribute); + var expectedBuilderAttribute = new KeyValuePair("for", "hello"); + tagBuilder.Attributes.Add("for", "hello"); // Act tagHelperOutput.MergeAttributes(tagBuilder); diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TextAreaTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TextAreaTagHelperTest.cs index 4cbfbae251..7b644bd765 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TextAreaTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TextAreaTagHelperTest.cs @@ -7,7 +7,6 @@ using System.Threading.Tasks; using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Razor.Runtime.TagHelpers; -using Microsoft.Framework.WebEncoders; using Xunit; namespace Microsoft.AspNet.Mvc.TagHelpers @@ -89,7 +88,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers string expectedContent) { // Arrange - var expectedAttributes = new Dictionary + var expectedAttributes = new Dictionary { { "class", "form-control" }, { "id", nameAndId.Id }, @@ -123,7 +122,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers tagHelperContent.SetContent("Something"); return Task.FromResult(tagHelperContent); }); - var htmlAttributes = new Dictionary + var htmlAttributes = new Dictionary { { "class", "form-control" }, }; diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationMessageTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationMessageTagHelperTest.cs index 5fc828640a..bfec75c2aa 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationMessageTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationMessageTagHelperTest.cs @@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers }); var output = new TagHelperOutput( expectedTagName, - attributes: new Dictionary + attributes: new Dictionary { { "id", "myvalidationmessage" } }); @@ -105,7 +105,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers }); var output = new TagHelperOutput( "span", - attributes: new Dictionary()); + attributes: new Dictionary()); output.PreContent.SetContent(expectedPreContent); output.Content.SetContent(expectedContent); output.PostContent.SetContent(expectedPostContent); @@ -145,7 +145,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers }; var output = new TagHelperOutput( "span", - attributes: new Dictionary()); + attributes: new Dictionary()); output.Content.SetContent(outputContent); var context = new TagHelperContext( @@ -204,7 +204,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers }; var output = new TagHelperOutput( "span", - attributes: new Dictionary()); + attributes: new Dictionary()); var context = new TagHelperContext( allAttributes: new Dictionary(), @@ -259,7 +259,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var expectedPostContent = "original post-content"; var output = new TagHelperOutput( "span", - attributes: new Dictionary()); + attributes: new Dictionary()); output.PreContent.SetContent(expectedPreContent); output.Content.SetContent(expectedContent); output.PostContent.SetContent(expectedPostContent); diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationSummaryTagHelperTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationSummaryTagHelperTest.cs index 4baef341e7..42ffd90f9a 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationSummaryTagHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/ValidationSummaryTagHelperTest.cs @@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers }); var output = new TagHelperOutput( expectedTagName, - attributes: new Dictionary + attributes: new Dictionary { { "class", "form-control" } }); @@ -102,7 +102,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var expectedPostContent = "original post-content"; var output = new TagHelperOutput( "div", - attributes: new Dictionary()); + attributes: new Dictionary()); output.PreContent.SetContent(expectedPreContent); output.Content.SetContent(expectedContent); output.PostContent.SetContent(expectedPostContent); @@ -144,7 +144,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var expectedContent = "original content"; var output = new TagHelperOutput( "div", - attributes: new Dictionary()); + attributes: new Dictionary()); output.PreContent.SetContent(expectedPreContent); output.Content.SetContent(expectedContent); output.PostContent.SetContent("Content of validation summary"); @@ -201,7 +201,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var expectedPostContent = "original post-content"; var output = new TagHelperOutput( "div", - attributes: new Dictionary()); + attributes: new Dictionary()); output.PreContent.SetContent(expectedPreContent); output.Content.SetContent(expectedContent); output.PostContent.SetContent(expectedPostContent); @@ -236,7 +236,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers var expectedContent = "original content"; var output = new TagHelperOutput( "div", - attributes: new Dictionary()); + attributes: new Dictionary()); output.PreContent.SetContent(expectedPreContent); output.Content.SetContent(expectedContent); output.PostContent.SetContent("Content of validation message"); diff --git a/test/Microsoft.AspNet.Mvc.TestCommon/TestHtmlEncoder.cs b/test/Microsoft.AspNet.Mvc.TestCommon/TestHtmlEncoder.cs new file mode 100644 index 0000000000..21cac68cf0 --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.TestCommon/TestHtmlEncoder.cs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; + +namespace Microsoft.Framework.WebEncoders +{ + internal class TestHtmlEncoder : IHtmlEncoder + { + public string HtmlEncode(string value) + { + return $"HtmlEncode[[{ value }]]"; + } + + public void HtmlEncode(string value, int startIndex, int charCount, TextWriter output) + { + output.Write($"HtmlEncode[[{ value.Substring(startIndex, charCount) }]]"); + } + + public void HtmlEncode(char[] value, int startIndex, int charCount, TextWriter output) + { + output.Write("HtmlEncode[["); + output.Write(value, startIndex, charCount); + output.Write("]]"); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.TestCommon/TestJavaScriptEncoder.cs b/test/Microsoft.AspNet.Mvc.TestCommon/TestJavaScriptEncoder.cs new file mode 100644 index 0000000000..214fad05e2 --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.TestCommon/TestJavaScriptEncoder.cs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; + +namespace Microsoft.Framework.WebEncoders +{ + internal class TestJavaScriptEncoder : IJavaScriptStringEncoder + { + public string JavaScriptStringEncode(string value) + { + return $"JavaScriptEncode[[{ value }]]"; + } + + public void JavaScriptStringEncode(string value, int startIndex, int charCount, TextWriter output) + { + output.Write($"JavaScriptEncode[[{ value.Substring(startIndex, charCount) }]]"); + } + + public void JavaScriptStringEncode(char[] value, int startIndex, int charCount, TextWriter output) + { + output.Write("JavaScriptEncode[["); + output.Write(value, startIndex, charCount); + output.Write("]]"); + } + } +} \ No newline at end of file diff --git a/test/Microsoft.AspNet.Mvc.TestCommon/TestUrlEncoder.cs b/test/Microsoft.AspNet.Mvc.TestCommon/TestUrlEncoder.cs new file mode 100644 index 0000000000..e3465a3620 --- /dev/null +++ b/test/Microsoft.AspNet.Mvc.TestCommon/TestUrlEncoder.cs @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.IO; + +namespace Microsoft.Framework.WebEncoders +{ + internal class TestUrlEncoder : IUrlEncoder + { + public string UrlEncode(string value) + { + return $"UrlEncode[[{ value }]]"; + } + + public void UrlEncode(string value, int startIndex, int charCount, TextWriter output) + { + output.Write($"UrlEncode[[{ value.Substring(startIndex, charCount) }]]"); + } + + public void UrlEncode(char[] value, int startIndex, int charCount, TextWriter output) + { + output.Write("UrlEncode[["); + output.Write(value, startIndex, charCount); + output.Write("]]"); + } + } +} \ No newline at end of file diff --git a/test/WebSites/MvcTagHelpersWebSite/Views/MvcTagHelper_Home/Index.cshtml b/test/WebSites/MvcTagHelpersWebSite/Views/MvcTagHelper_Home/Index.cshtml index b9b1d201d0..6645b9131e 100644 --- a/test/WebSites/MvcTagHelpersWebSite/Views/MvcTagHelper_Home/Index.cshtml +++ b/test/WebSites/MvcTagHelpersWebSite/Views/MvcTagHelper_Home/Index.cshtml @@ -7,10 +7,10 @@
MvcTagHelperTest Index diff --git a/test/WebSites/MvcTagHelpersWebSite/Views/MvcTagHelper_Home/Link.cshtml b/test/WebSites/MvcTagHelpersWebSite/Views/MvcTagHelper_Home/Link.cshtml index 08f42bc575..460d97a620 100644 --- a/test/WebSites/MvcTagHelpersWebSite/Views/MvcTagHelper_Home/Link.cshtml +++ b/test/WebSites/MvcTagHelpersWebSite/Views/MvcTagHelper_Home/Link.cshtml @@ -7,13 +7,13 @@ Link - + - + - + @@ -37,8 +37,8 @@ - diff --git a/test/WebSites/MvcTagHelpersWebSite/Views/MvcTagHelper_Home/Script.cshtml b/test/WebSites/MvcTagHelpersWebSite/Views/MvcTagHelper_Home/Script.cshtml index 861d1a9779..1945aab3c5 100644 --- a/test/WebSites/MvcTagHelpersWebSite/Views/MvcTagHelper_Home/Script.cshtml +++ b/test/WebSites/MvcTagHelpersWebSite/Views/MvcTagHelper_Home/Script.cshtml @@ -11,15 +11,15 @@

Script tag helper test

- - - diff --git a/test/WebSites/TagHelpersWebSite/TagHelpers/PrettyTagHelper.cs b/test/WebSites/TagHelpersWebSite/TagHelpers/PrettyTagHelper.cs index 8ae7fc18c8..5bc7a2b5be 100644 --- a/test/WebSites/TagHelpersWebSite/TagHelpers/PrettyTagHelper.cs +++ b/test/WebSites/TagHelpersWebSite/TagHelpers/PrettyTagHelper.cs @@ -23,12 +23,14 @@ namespace TagHelpersWebSite.TagHelpers public bool? MakePretty { get; set; } + public string Style { get; set; } + [Activate] public ViewContext ViewContext { get; set; } public override void Process(TagHelperContext context, TagHelperOutput output) { - // Need to check if output.TagName == null in-case the ConditionTagHelper calls into SuppressOutput and + // Need to check if output.TagName == null in-case the ConditionTagHelper calls into SuppressOutput and // therefore sets the TagName to null. if (MakePretty.HasValue && !MakePretty.Value || output.TagName == null) @@ -40,9 +42,8 @@ namespace TagHelpersWebSite.TagHelpers if (PrettyTagStyles.TryGetValue(output.TagName, out prettyStyle)) { - var style = string.Empty; - - if (output.Attributes.TryGetValue("style", out style)) + var style = Style ?? string.Empty; + if (!string.IsNullOrEmpty(style)) { style += ";"; }