diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/ImageTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/ImageTagHelper.cs
index 47d7e365a2..3133a360ce 100644
--- a/src/Microsoft.AspNet.Mvc.TagHelpers/ImageTagHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.TagHelpers/ImageTagHelper.cs
@@ -75,23 +75,20 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
///
public override void Process(TagHelperContext context, TagHelperOutput output)
{
+ output.CopyHtmlAttribute(SrcAttributeName, context);
+ ProcessUrlAttribute(SrcAttributeName, output);
+
if (AppendVersion)
{
EnsureFileVersionProvider();
- string resolvedUrl;
- if (TryResolveUrl(Src, encodeWebRoot: false, resolvedUrl: out resolvedUrl))
- {
- Src = resolvedUrl;
- }
+ // Retrieve the TagHelperOutput variation of the "src" attribute in case other TagHelpers in the
+ // pipeline have touched the value. If the value is already encoded this ImageTagHelper may
+ // not function properly.
+ Src = output.Attributes[SrcAttributeName].Value as string;
+
output.Attributes[SrcAttributeName] = _fileVersionProvider.AddFileVersionToPath(Src);
}
- else
- {
- // Pass through attribute that is also a well-known HTML attribute.
- output.CopyHtmlAttribute(SrcAttributeName, context);
- ProcessUrlAttribute(SrcAttributeName, output);
- }
}
private void EnsureFileVersionProvider()
diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs
index cf9069b3b2..ecd0365d2e 100644
--- a/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.TagHelpers/LinkTagHelper.cs
@@ -211,16 +211,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
if (Href != null)
{
output.CopyHtmlAttribute(HrefAttributeName, context);
-
- // Resolve any application relative URLs (~/) now so they can be used in comparisons later.
- if (TryResolveUrl(Href, encodeWebRoot: false, resolvedUrl: out resolvedUrl))
- {
- Href = resolvedUrl;
- }
-
- ProcessUrlAttribute(HrefAttributeName, output);
}
+ // If there's no "href" attribute in output.Attributes this will noop.
+ ProcessUrlAttribute(HrefAttributeName, output);
+
+ // Retrieve the TagHelperOutput variation of the "href" attribute in case other TagHelpers in the
+ // pipeline have touched the value. If the value is already encoded this LinkTagHelper may
+ // not function properly.
+ Href = output.Attributes[HrefAttributeName]?.Value as string;
+
var modeResult = AttributeMatcher.DetermineMode(context, ModeDetails);
modeResult.LogDetails(Logger, this, context.UniqueId, ViewContext.View.Path);
@@ -238,11 +238,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{
EnsureFileVersionProvider();
- var attributeStringValue = output.Attributes[HrefAttributeName]?.Value as string;
- if (attributeStringValue != null)
+ if (Href != null)
{
- output.Attributes[HrefAttributeName].Value =
- _fileVersionProvider.AddFileVersionToPath(attributeStringValue);
+ output.Attributes[HrefAttributeName].Value = _fileVersionProvider.AddFileVersionToPath(Href);
}
}
diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/ScriptTagHelper.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/ScriptTagHelper.cs
index 94ceb57985..76cda41b99 100644
--- a/src/Microsoft.AspNet.Mvc.TagHelpers/ScriptTagHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.TagHelpers/ScriptTagHelper.cs
@@ -179,15 +179,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
if (Src != null)
{
output.CopyHtmlAttribute(SrcAttributeName, context);
-
- if (TryResolveUrl(Src, encodeWebRoot: false, resolvedUrl: out resolvedUrl))
- {
- Src = resolvedUrl;
- }
-
- ProcessUrlAttribute(SrcAttributeName, output);
}
+ // If there's no "src" attribute in output.Attributes this will noop.
+ ProcessUrlAttribute(SrcAttributeName, output);
+
+ // Retrieve the TagHelperOutput variation of the "src" attribute in case other TagHelpers in the
+ // pipeline have touched the value. If the value is already encoded this ScriptTagHelper may
+ // not function properly.
+ Src = output.Attributes[SrcAttributeName]?.Value as string;
+
var modeResult = AttributeMatcher.DetermineMode(context, ModeDetails);
modeResult.LogDetails(Logger, this, context.UniqueId, ViewContext.View.Path);
@@ -205,11 +206,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{
EnsureFileVersionProvider();
- var attributeStringValue = output.Attributes[SrcAttributeName]?.Value as string;
- if (attributeStringValue != null)
+ if (Src != null)
{
- output.Attributes[SrcAttributeName].Value =
- _fileVersionProvider.AddFileVersionToPath(attributeStringValue);
+ output.Attributes[SrcAttributeName].Value = _fileVersionProvider.AddFileVersionToPath(Src);
}
}
diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Image.html b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Image.html
index a8557e52a3..95b1559a10 100644
--- a/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Image.html
+++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/compiler/resources/HtmlGenerationWebSite.HtmlGeneration_Home.Image.html
@@ -12,24 +12,24 @@
-
+
-
+
-
+
-
+
-
+
-
+