From 6213354b85ee4b0e7c42d0eb64fc76447e28e9fb Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Mon, 29 Jun 2015 12:52:23 -0700 Subject: [PATCH] Fixes for FileVersionProvider - Path with query string works - No exception is thrown for absolute path --- .../Internal/FileVersionProvider.cs | 14 ++++++++++++++ ...erationWebSite.HtmlGeneration_Home.Image.html | 16 ++++++++++++++-- .../Views/HtmlGeneration_Home/Image.cshtml | 16 ++++++++++++++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/FileVersionProvider.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/FileVersionProvider.cs index cff00bc974..b8bad61709 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/FileVersionProvider.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/FileVersionProvider.cs @@ -48,6 +48,20 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal public string AddFileVersionToPath([NotNull] string path) { var resolvedPath = path; + + var queryStringStartIndex = path.IndexOf('?'); + if (queryStringStartIndex != -1) + { + resolvedPath = path.Substring(0, queryStringStartIndex); + } + + Uri uri; + if (Uri.TryCreate(resolvedPath, UriKind.Absolute, out uri)) + { + // Don't append version if the path is absolute. + return path; + } + var fileInfo = _fileProvider.GetFileInfo(resolvedPath); if (!fileInfo.Exists) { 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 148485f395..a102c65158 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 @@ -11,10 +11,22 @@ Red block - + Red versioned - + Red explicitly not versioned + + + Absolute path versioned + + + Path to non existing file + + + Path with query string + + + Path linking to some action \ No newline at end of file diff --git a/test/WebSites/HtmlGenerationWebSite/Views/HtmlGeneration_Home/Image.cshtml b/test/WebSites/HtmlGenerationWebSite/Views/HtmlGeneration_Home/Image.cshtml index 9a5052c828..95f9ec3873 100644 --- a/test/WebSites/HtmlGenerationWebSite/Views/HtmlGeneration_Home/Image.cshtml +++ b/test/WebSites/HtmlGenerationWebSite/Views/HtmlGeneration_Home/Image.cshtml @@ -13,10 +13,22 @@ Red block - + Red versioned - + Red explicitly not versioned + + + Absolute path versioned + + + Path to non existing file + + + Path with query string + + + Path linking to some action \ No newline at end of file