private void AppendAttribute(TagHelperContent content, string key, object value, bool escapeQuotes) { content .AppendEncoded(" ") .AppendEncoded(key); if (escapeQuotes) { // Passed only JavaScript-encoded strings in this case. Do not perform HTML-encoding as well. content .AppendEncoded("=\\\"") .AppendEncoded((string)value) .AppendEncoded("\\\""); } else { // HTML-encoded the given value if necessary. content .AppendEncoded("=\"") .Append(HtmlEncoder, ViewContext.Writer.Encoding, value) .AppendEncoded("\""); } }
private void BuildScriptTag( TagHelperAttributeList attributes, TagHelperContent builder) { builder.AppendEncoded("<script"); foreach (var attribute in attributes) { var attributeValue = attribute.Value; if (AppendVersion == true && string.Equals(attribute.Name, SrcAttributeName, StringComparison.OrdinalIgnoreCase)) { // "src" values come from bound attributes and globbing. So anything but a non-null string is // unexpected but could happen if another helper targeting the same element does something odd. // Pass through existing value in that case. var attributeStringValue = attributeValue as string; if (attributeStringValue != null) { attributeValue = _fileVersionProvider.AddFileVersionToPath(attributeStringValue); } } AppendAttribute(builder, attribute.Name, attributeValue, escapeQuotes: false); } builder.AppendEncoded("></script>"); }
private void BuildFallbackBlock(TagHelperContent builder) { EnsureGlobbingUrlBuilder(); var fallbackHrefs = GlobbingUrlBuilder.BuildUrlList(FallbackHref, FallbackHrefInclude, FallbackHrefExclude).ToArray(); if (fallbackHrefs.Length > 0) { if (AppendVersion == 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]); } } builder.Append(HtmlString.NewLine); // Build the <meta /> tag that's used to test for the presence of the stylesheet builder .AppendEncoded("<meta name=\"x-stylesheet-fallback-test\" class=\"") .Append(FallbackTestClass) .AppendEncoded("\" />"); // Build the <script /> tag that checks the effective style of <meta /> tag above and renders the extra // <link /> tag to load the fallback stylesheet if the test CSS property value is found to be false, // indicating that the primary stylesheet failed to load. builder .AppendEncoded("<script>") .AppendEncoded( string.Format( CultureInfo.InvariantCulture, JavaScriptResources.GetEmbeddedJavaScript(FallbackJavaScriptResourceName), JavaScriptEncoder.JavaScriptStringEncode(FallbackTestProperty), JavaScriptEncoder.JavaScriptStringEncode(FallbackTestValue), JavaScriptStringArrayEncoder.Encode(JavaScriptEncoder, fallbackHrefs))) .AppendEncoded("</script>"); } }
private void BuildLinkTag(TagHelperAttributeList attributes, TagHelperContent builder) { builder.AppendEncoded("<link "); foreach (var attribute in attributes) { var attributeValue = attribute.Value; if (AppendVersion == true && string.Equals(attribute.Name, HrefAttributeName, StringComparison.OrdinalIgnoreCase)) { // "href" values come from bound attributes and globbing. So anything but a non-null string is // unexpected but could happen if another helper targeting the same element does something odd. // Pass through existing value in that case. var attributeStringValue = attributeValue as string; if (attributeStringValue != null) { attributeValue = _fileVersionProvider.AddFileVersionToPath(attributeStringValue); } } builder .AppendEncoded(attribute.Name) .AppendEncoded("=\"") .Append(HtmlEncoder, ViewContext.Writer.Encoding, attributeValue) .AppendEncoded("\" "); } builder.AppendEncoded("/>"); }
private void BuildScriptTag( TagHelperAttributeList attributes, TagHelperContent builder) { // AppendHtml in latest code, AppendEncoded in beta8 nugets builder.AppendEncoded("<script"); foreach (var attribute in attributes) { var attributeValue = attribute.Value; AppendAttribute(builder, attribute.Name, attributeValue, escapeQuotes: false); } builder.AppendEncoded("></script>"); }