From ecc089a7a64b51996d89a13cbab14d476723cd54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20Bartha?= Date: Wed, 15 May 2019 17:52:00 +0200 Subject: [PATCH] DisplayManagement: Fixing that stylesheets that don't exist shouldn't create shapes (#8199) --- .../StylesheetBindingStrategy.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Orchard/DisplayManagement/Descriptors/ResourceBindingStrategy/StylesheetBindingStrategy.cs b/src/Orchard/DisplayManagement/Descriptors/ResourceBindingStrategy/StylesheetBindingStrategy.cs index bc0e93fd0..1f96d3e83 100644 --- a/src/Orchard/DisplayManagement/Descriptors/ResourceBindingStrategy/StylesheetBindingStrategy.cs +++ b/src/Orchard/DisplayManagement/Descriptors/ResourceBindingStrategy/StylesheetBindingStrategy.cs @@ -92,16 +92,29 @@ namespace Orchard.DisplayManagement.Descriptors.ResourceBindingStrategy { var shape = ((dynamic)displayContext.Value); var output = displayContext.ViewContext.Writer; ResourceDefinition resource = shape.Resource; - string url = shape.Url; + var url = GetResourceUrl(shape.Url, hit.fileVirtualPath); string condition = shape.Condition; Dictionary attributes = shape.TagAttributes; - ResourceManager.WriteResource(output, resource, url ?? hit.fileVirtualPath, condition, attributes); + ResourceManager.WriteResource(output, resource, url, condition, attributes); return null; }); } } } + private string GetResourceUrl(string shapeUrl, string fileVirtualPath) { + if (string.IsNullOrEmpty(shapeUrl)) return fileVirtualPath; + + return GetPathFromRelativeUrl(shapeUrl) == GetPathFromRelativeUrl(fileVirtualPath) ? shapeUrl : fileVirtualPath; + } + + private string GetPathFromRelativeUrl(string url) { + var path = url.TrimStart('~'); + var indexOfQueryString = path.IndexOf('?'); + + return indexOfQueryString >= 0 ? path.Substring(0, indexOfQueryString) : path; + } + private bool FeatureIsEnabled(FeatureDescriptor fd) { return (DefaultExtensionTypes.IsTheme(fd.Extension.ExtensionType) && (fd.Id == "TheAdmin" || fd.Id == "SafeMode")) || _shellDescriptor.Features.Any(sf => sf.Name == fd.Id);