From 55f2fb24c2f5f487083b08f88def15a3937ad448 Mon Sep 17 00:00:00 2001 From: Bertrand Le Roy Date: Thu, 4 Jun 2015 11:01:46 -0700 Subject: [PATCH] Fix the case of protocol-less stylesheet URI. .NET's Uri.IsWellFormedUriString doesn't understand protocol-less URI, resulting in the stylesheet binding strategy mistaking those for local resources, and trying to find alternates. This is wasteful and can lead to subtle bugs. If the method is ever fixed, the new code will die, and everything sill continue to work as expected. --- .../ResourceBindingStrategy/StylesheetBindingStrategy.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Orchard/DisplayManagement/Descriptors/ResourceBindingStrategy/StylesheetBindingStrategy.cs b/src/Orchard/DisplayManagement/Descriptors/ResourceBindingStrategy/StylesheetBindingStrategy.cs index ec71eb2fb..f6488232a 100644 --- a/src/Orchard/DisplayManagement/Descriptors/ResourceBindingStrategy/StylesheetBindingStrategy.cs +++ b/src/Orchard/DisplayManagement/Descriptors/ResourceBindingStrategy/StylesheetBindingStrategy.cs @@ -16,7 +16,7 @@ namespace Orchard.DisplayManagement.Descriptors.ResourceBindingStrategy { private readonly IExtensionManager _extensionManager; private readonly ShellDescriptor _shellDescriptor; private readonly IVirtualPathProvider _virtualPathProvider; - private static readonly char[] unsafeCharList = "/:?#[]@!&'()*+,;=\r\n\t\f\" <>.-_".ToCharArray(); + private static readonly char[] UnsafeCharList = "/:?#[]@!&'()*+,;=\r\n\t\f\" <>.-_".ToCharArray(); protected StaticFileBindingStrategy(IExtensionManager extensionManager, ShellDescriptor shellDescriptor, IVirtualPathProvider virtualPathProvider) { _extensionManager = extensionManager; @@ -32,7 +32,7 @@ namespace Orchard.DisplayManagement.Descriptors.ResourceBindingStrategy { if (string.IsNullOrWhiteSpace(name)) return String.Empty; - return name.Strip(unsafeCharList).ToLowerInvariant(); + return name.Strip(UnsafeCharList).ToLowerInvariant(); } public static string GetAlternateShapeNameFromFileName(string fileName) { @@ -40,7 +40,9 @@ namespace Orchard.DisplayManagement.Descriptors.ResourceBindingStrategy { throw new ArgumentNullException("fileName"); } string shapeName; - if (Uri.IsWellFormedUriString(fileName, UriKind.Absolute)) { + if (Uri.IsWellFormedUriString(fileName, UriKind.Absolute) + || (fileName.StartsWith("//", StringComparison.InvariantCulture) + && Uri.IsWellFormedUriString("http:" + fileName, UriKind.Absolute))) { var uri = new Uri(fileName); shapeName = uri.Authority + "$" + uri.AbsolutePath + "$" + uri.Query; }