Skip to content

Commit

Permalink
SLING-9718 - Relative paths for bundled HTL template files are not co…
Browse files Browse the repository at this point in the history
…rrectly 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
  • Loading branch information
raducotescu committed Sep 3, 2020
1 parent 960d9cd commit 65c4814
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,18 @@ public RenderUnit getRenderUnit(@NotNull Bindings bindings) {
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) {
Expand All @@ -129,10 +136,8 @@ public RenderUnit getRenderUnit(@NotNull Bindings bindings, @NotNull String iden
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("/")) {
Expand Down Expand Up @@ -185,8 +190,7 @@ public URL getScript(Bindings bindings, String identifier) {
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public ProviderOutcome provide(String identifier, RenderContext renderContext, B
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);
}
Expand Down

0 comments on commit 65c4814

Please sign in to comment.