Explicitly check if URI is file when checking for an absolute URI

This commit is contained in:
Daniel Lo Nigro 2015-08-15 23:18:40 -07:00 committed by Doug Bunting
parent 55fc7ded36
commit a2e53e8d1a
6 changed files with 21 additions and 63 deletions

View File

@ -56,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
} }
Uri uri; Uri uri;
if (Uri.TryCreate(resolvedPath, UriKind.Absolute, out uri)) if (Uri.TryCreate(resolvedPath, UriKind.Absolute, out uri) && !uri.IsFile)
{ {
// Don't append version if the path is absolute. // Don't append version if the path is absolute.
return path; return path;

View File

@ -59,12 +59,6 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
[InlineData("AttributesWithBooleanValues", null)] [InlineData("AttributesWithBooleanValues", null)]
public async Task HtmlGenerationWebSite_GeneratesExpectedResults(string action, string antiforgeryPath) public async Task HtmlGenerationWebSite_GeneratesExpectedResults(string action, string antiforgeryPath)
{ {
// This uses FileVersionProvider which uses Uri.TryCreate - https://github.com/aspnet/External/issues/21
if (TestPlatformHelper.IsMono && (action == "Link" || action == "Script" || action == "Image"))
{
return;
}
// Arrange // Arrange
var server = TestHelper.CreateServer(_app, SiteName, _configureServices); var server = TestHelper.CreateServer(_app, SiteName, _configureServices);
var client = server.CreateClient(); var client = server.CreateClient();
@ -124,12 +118,6 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
[InlineData("AttributesWithBooleanValues", null)] [InlineData("AttributesWithBooleanValues", null)]
public async Task HtmlGenerationWebSite_GenerateEncodedResults(string action, string antiforgeryPath) public async Task HtmlGenerationWebSite_GenerateEncodedResults(string action, string antiforgeryPath)
{ {
// This uses FileVersionProvider which uses Uri.TryCreate - https://github.com/aspnet/External/issues/21
if (TestPlatformHelper.IsMono && (action == "Link" || action == "Script"))
{
return;
}
// Arrange // Arrange
var server = TestHelper.CreateServer(_app, SiteName, services => var server = TestHelper.CreateServer(_app, SiteName, services =>
{ {
@ -582,4 +570,4 @@ Products: Laptops (3)";
Assert.Equal(expected, response); Assert.Equal(expected, response);
} }
} }
} }

View File

@ -135,9 +135,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
} }
} }
[ConditionalTheory] [Fact]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
public void RendersImageTag_AddsFileVersion() public void RendersImageTag_AddsFileVersion()
{ {
// Arrange // Arrange
@ -209,9 +207,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Assert.Equal("/images/test-image.png", srcAttribute.Value); Assert.Equal("/images/test-image.png", srcAttribute.Value);
} }
[ConditionalTheory] [Fact]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
public void RendersImageTag_AddsFileVersion_WithRequestPathBase() public void RendersImageTag_AddsFileVersion_WithRequestPathBase()
{ {
// Arrange // Arrange
@ -337,4 +333,4 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
return urlHelper.Object; return urlHelper.Object;
} }
} }
} }

View File

@ -17,9 +17,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
{ {
public class FileVersionProviderTest public class FileVersionProviderTest
{ {
[ConditionalTheory] [Theory]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[InlineData("/hello/world", "/hello/world?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk")] [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=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", "/hello/world?q=foo&bar&v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk")]
@ -42,9 +40,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
} }
// Verifies if the stream is closed after reading. // Verifies if the stream is closed after reading.
[ConditionalTheory] [Fact]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
public void AddsVersionToFiles_DoesNotLockFileAfterReading() public void AddsVersionToFiles_DoesNotLockFileAfterReading()
{ {
// Arrange // Arrange
@ -75,9 +71,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
Assert.Throws<ObjectDisposedException>(() => fileVersionProvider.AddFileVersionToPath("/hello/world")); Assert.Throws<ObjectDisposedException>(() => fileVersionProvider.AddFileVersionToPath("/hello/world"));
} }
[ConditionalTheory] [Theory]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[InlineData("/testApp/hello/world", true, "/testApp")] [InlineData("/testApp/hello/world", true, "/testApp")]
[InlineData("/testApp/foo/bar/hello/world", true, "/testApp/foo/bar")] [InlineData("/testApp/foo/bar/hello/world", true, "/testApp/foo/bar")]
[InlineData("/test/testApp/hello/world", false, "/testApp")] [InlineData("/test/testApp/hello/world", false, "/testApp")]
@ -100,9 +94,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
Assert.Equal(filePath + "?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk", result); Assert.Equal(filePath + "?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk", result);
} }
[ConditionalTheory] [Fact]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
public void DoesNotAddVersion_IfFileNotFound() public void DoesNotAddVersion_IfFileNotFound()
{ {
// Arrange // Arrange
@ -120,9 +112,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
Assert.Equal("http://contoso.com/hello/world", result); Assert.Equal("http://contoso.com/hello/world", result);
} }
[ConditionalTheory] [Fact]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
public void ReturnsValueFromCache() public void ReturnsValueFromCache()
{ {
// Arrange // Arrange
@ -140,9 +130,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
Assert.Equal("FromCache", result); Assert.Equal("FromCache", result);
} }
[ConditionalTheory] [Theory]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
[InlineData("/hello/world", "/hello/world", null)] [InlineData("/hello/world", "/hello/world", null)]
[InlineData("/testApp/hello/world", "/hello/world", "/testApp")] [InlineData("/testApp/hello/world", "/hello/world", "/testApp")]
public void SetsValueInCache(string filePath, string watchPath, string requestPathBase) public void SetsValueInCache(string filePath, string watchPath, string requestPathBase)
@ -235,4 +223,4 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
return new PathString(requestPathBase); return new PathString(requestPathBase);
} }
} }
} }

View File

@ -678,9 +678,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
output.PostElement.GetContent()); output.PostElement.GetContent());
} }
[ConditionalTheory] [Fact]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
public void RendersLinkTags_AddsFileVersion() public void RendersLinkTags_AddsFileVersion()
{ {
// Arrange // Arrange
@ -720,9 +718,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Assert.Equal("/css/site.css?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk", output.Attributes["href"].Value); Assert.Equal("/css/site.css?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk", output.Attributes["href"].Value);
} }
[ConditionalTheory] [Fact]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
public void RendersLinkTags_AddsFileVersion_WithRequestPathBase() public void RendersLinkTags_AddsFileVersion_WithRequestPathBase()
{ {
// Arrange // Arrange
@ -762,9 +758,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Assert.Equal("/bar/css/site.css?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk", output.Attributes["href"].Value); Assert.Equal("/bar/css/site.css?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk", output.Attributes["href"].Value);
} }
[ConditionalTheory] [Fact]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
public void RendersLinkTags_GlobbedHref_AddsFileVersion() public void RendersLinkTags_GlobbedHref_AddsFileVersion()
{ {
// Arrange // Arrange
@ -914,4 +908,4 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
return urlHelper.Object; return urlHelper.Object;
} }
} }
} }

View File

@ -733,9 +733,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Assert.Equal("<script src=\"HtmlEncode[[/common.js]]\"></script>", output.PostElement.GetContent()); Assert.Equal("<script src=\"HtmlEncode[[/common.js]]\"></script>", output.PostElement.GetContent());
} }
[ConditionalTheory] [Fact]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
public async Task RenderScriptTags_WithFileVersion() public async Task RenderScriptTags_WithFileVersion()
{ {
// Arrange // Arrange
@ -772,9 +770,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Assert.Equal("/js/site.js?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk", output.Attributes["src"].Value); Assert.Equal("/js/site.js?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk", output.Attributes["src"].Value);
} }
[ConditionalTheory] [Fact]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
public async Task RenderScriptTags_WithFileVersion_AndRequestPathBase() public async Task RenderScriptTags_WithFileVersion_AndRequestPathBase()
{ {
// Arrange // Arrange
@ -811,9 +807,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
Assert.Equal("/bar/js/site.js?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk", output.Attributes["src"].Value); Assert.Equal("/bar/js/site.js?v=f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk", output.Attributes["src"].Value);
} }
[ConditionalTheory] [Fact]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
public async Task RenderScriptTags_FallbackSrc_WithFileVersion() public async Task RenderScriptTags_FallbackSrc_WithFileVersion()
{ {
// Arrange // Arrange
@ -857,9 +851,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
"<\\/script>\"));</script>", output.PostElement.GetContent()); "<\\/script>\"));</script>", output.PostElement.GetContent());
} }
[ConditionalTheory] [Fact]
// Mono issue - https://github.com/aspnet/External/issues/21
[FrameworkSkipCondition(RuntimeFrameworks.Mono)]
public async Task RenderScriptTags_GlobbedSrc_WithFileVersion() public async Task RenderScriptTags_GlobbedSrc_WithFileVersion()
{ {
// Arrange // Arrange
@ -1012,4 +1004,4 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
return urlHelper.Object; return urlHelper.Object;
} }
} }
} }