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
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 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 @@
                     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 @@
         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 @@
             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);
                     }