Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
[Fixes #2862] asp-append-version now works with urls containing fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaybhargavb committed Jul 29, 2015
1 parent 260ac29 commit f21bf92
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public string AddFileVersionToPath([NotNull] string path)
{
var resolvedPath = path;

var queryStringStartIndex = path.IndexOf('?');
if (queryStringStartIndex != -1)
var queryStringOrFragmentStartIndex = path.IndexOfAny(new char[] { '?', '#' });
if (queryStringOrFragmentStartIndex != -1)
{
resolvedPath = path.Substring(0, queryStringStartIndex);
resolvedPath = path.Substring(0, queryStringOrFragmentStartIndex);
}

Uri uri;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ <h2>Image Tag Helper Test</h2>
<!-- Plain image tag with file version and path containing query string -->
<img alt="Path with query string" src="/images/red.png?abc=def&amp;v=W2F5D366_nQ2fQqUk3URdgWy2ZekXjHzHJaY5yaiOOk" />

<!-- Plain image tag with file version and path containing fragment -->
<img alt="Path with query string" src="/images/red.png?v=W2F5D366_nQ2fQqUk3URdgWy2ZekXjHzHJaY5yaiOOk#abc" />

<!-- Plain image tag with file version and path linking to some action -->
<img alt="Path linking to some action" src="/controller/action" />
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void PreservesOrderOfSourceAttributesWhenRun()
attributes: new TagHelperAttributeList
{
{ "alt", new HtmlString("alt text") },
{ "data-extra", new HtmlString("something") },
{ "data-extra", new HtmlString("something") },
{ "title", new HtmlString("Image title") },
{ "src", "testimage.png" },
{ "asp-append-version", "true" }
Expand All @@ -42,7 +42,7 @@ public void PreservesOrderOfSourceAttributesWhenRun()
attributes: new TagHelperAttributeList
{
{ "alt", new HtmlString("alt text") },
{ "data-extra", new HtmlString("something") },
{ "data-extra", new HtmlString("something") },
{ "title", new HtmlString("Image title") },
});

Expand All @@ -68,10 +68,10 @@ public void PreservesOrderOfSourceAttributesWhenRun()
// Act
helper.Process(context, output);

// Assert
// Assert
Assert.Equal(expectedOutput.TagName, output.TagName);
Assert.Equal(4, output.Attributes.Count);

for(int i=0; i < expectedOutput.Attributes.Count; i++)
{
var expectedAtribute = expectedOutput.Attributes[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class FileVersionProviderTest
[InlineData("/hello/world", "/hello/world?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk")]
[InlineData("/hello/world?q=test", "/hello/world?q=test&v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk")]
[InlineData("/hello/world?q=foo&bar", "/hello/world?q=foo&bar&v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk")]
[InlineData("/hello/world?q=foo&bar#abc", "/hello/world?q=foo&bar&v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk#abc")]
[InlineData("/hello/world#somefragment", "/hello/world?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk#somefragment")]
public void AddsVersionToFiles_WhenCacheIsAbsent(string filePath, string expected)
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<!-- Plain image tag with file version and path containing query string -->
<img src="~/images/red.png?abc=def" alt="Path with query string" asp-append-version="true" />

<!-- Plain image tag with file version and path containing fragment -->
<img src="~/images/red.png#abc" alt="Path with query string" asp-append-version="true" />

<!-- Plain image tag with file version and path linking to some action -->
<img src="/controller/action" alt="Path linking to some action" asp-append-version="true" />
</body>
Expand Down

0 comments on commit f21bf92

Please sign in to comment.