You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2020/09/03 16:56:53 UTC
[sling-org-apache-sling-scripting-sightly] branch master updated:
SLING-9718 - Relative paths for bundled HTL template files are not
correctly handled
This is an automated email from the ASF dual-hosted git repository.
radu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-scripting-sightly.git
The following commit(s) were added to refs/heads/master by this push:
new 65c4814 SLING-9718 - Relative paths for bundled HTL template files are not correctly handled
65c4814 is described below
commit 65c481435fe664ff1a6c7fc66026c0d1c38f1489
Author: Radu Cotescu <ra...@apache.org>
AuthorDate: Thu Sep 3 18:49:04 2020 +0200
SLING-9718 - Relative paths for bundled HTL template files are not correctly handled
* if a servlet resource is found, work directly with its path to find the script class
or bundle entry
* corrected class name / file name when working with identifiers containing
relative path segments
---
.../engine/bundled/BundledUnitManagerImpl.java | 24 +++++++++++++---------
.../engine/extension/use/RenderUnitProvider.java | 2 +-
2 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/bundled/BundledUnitManagerImpl.java b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/bundled/BundledUnitManagerImpl.java
index 13d88a3..1676bf8 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/bundled/BundledUnitManagerImpl.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/bundled/BundledUnitManagerImpl.java
@@ -115,11 +115,18 @@ public class BundledUnitManagerImpl implements BundledUnitManager {
public RenderUnit getRenderUnit(@NotNull Bindings bindings, @NotNull String identifier) {
BundledRenderUnit bundledRenderUnit = getBundledRenderUnit(bindings);
Resource currentResource = BindingsUtils.getResource(bindings);
- List<String> searchPathRelativeLocations = new ArrayList<>();
- if (!identifier.startsWith("/")) {
- ResourceResolver scriptingResourceResolver = scriptingResourceResolverProvider.getRequestScopedResourceResolver();
- for (String searchPath : scriptingResourceResolver.getSearchPath()) {
- searchPathRelativeLocations.add(ResourceUtil.normalize(searchPath + "/" + identifier));
+ Set<String> defaultLocations = new LinkedHashSet<>();
+ for (String searchPath : scriptingResourceResolverProvider.getRequestScopedResourceResolver().getSearchPath()) {
+ if (identifier.startsWith("/")) {
+ defaultLocations.add(identifier);
+ if (identifier.startsWith(searchPath)) {
+ defaultLocations.add(identifier.substring(searchPath.length()));
+ }
+ } else {
+ String path = ResourceUtil.normalize(searchPath + "/" + identifier);
+ if (path != null) {
+ defaultLocations.add(path);
+ }
}
}
if (currentResource != null && bundledRenderUnit != null) {
@@ -129,10 +136,8 @@ public class BundledUnitManagerImpl implements BundledUnitManager {
for (ResourceType type : provider.getBundledRenderUnitCapability().getResourceTypes()) {
locations.add(getResourceTypeQualifiedPath(identifier, type));
}
- locations.addAll(searchPathRelativeLocations);
- } else {
- locations.add(identifier);
}
+ locations.addAll(defaultLocations);
for (String renderUnitIdentifier : locations) {
String renderUnitBundledPath = renderUnitIdentifier;
if (renderUnitBundledPath.startsWith("/")) {
@@ -185,8 +190,7 @@ public class BundledUnitManagerImpl implements BundledUnitManager {
if (currentResource != null && bundledRenderUnit != null) {
for (TypeProvider provider : bundledRenderUnit.getTypeProviders()) {
for (ResourceType type : provider.getBundledRenderUnitCapability().getResourceTypes()) {
- String scriptResourcePath = getResourceTypeQualifiedPath(identifier, type);
- String scriptBundledPath = scriptResourcePath;
+ String scriptBundledPath = getResourceTypeQualifiedPath(identifier, type);
if (scriptBundledPath.startsWith("/")) {
scriptBundledPath = scriptBundledPath.substring(1);
}
diff --git a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/RenderUnitProvider.java b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/RenderUnitProvider.java
index fe3de7e..22ab065 100644
--- a/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/RenderUnitProvider.java
+++ b/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/use/RenderUnitProvider.java
@@ -117,7 +117,7 @@ public class RenderUnitProvider implements UseProvider {
try {
if ("true".equalsIgnoreCase((String) renderUnitResource.getResourceMetadata().get("sling.servlet.resource"))) {
// bundled dependency
- RenderUnit renderUnit = bundledUnitManager.getRenderUnit(globalBindings, identifier);
+ RenderUnit renderUnit = bundledUnitManager.getRenderUnit(globalBindings, renderUnitResource.getPath());
if (renderUnit != null) {
return ProviderOutcome.success(renderUnit);
}