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/04/09 16:31:42 UTC
[sling-org-apache-sling-servlets-resolver] branch master updated:
SLING-9348 - ResourceCollector is not weighing scripts with a method in the
name correctly
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-servlets-resolver.git
The following commit(s) were added to refs/heads/master by this push:
new fc79361 SLING-9348 - ResourceCollector is not weighing scripts with a method in the name correctly
fc79361 is described below
commit fc79361ee30f0afa7978b4542a515e9a38fd6919
Author: Karl Pauls <pa...@apache.org>
AuthorDate: Thu Apr 9 18:31:36 2020 +0200
SLING-9348 - ResourceCollector is not weighing scripts with a method in the name correctly
* increase the weight for scripts with the method in their name
---
.../resolver/internal/helper/ResourceCollector.java | 4 ++--
.../servlets/resolver/internal/helper/WeightedResource.java | 6 ++++++
.../resolver/internal/helper/ResourceCollectorTest.java | 13 +++++++++++++
3 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollector.java b/src/main/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollector.java
index 689e249..636912a 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollector.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollector.java
@@ -295,13 +295,13 @@ public class ResourceCollector extends AbstractResourceCollector {
if (matches(scriptName, parentName, suffix)) {
addWeightedResource(resources, child, selIdx,
WeightedResource.WEIGHT_EXTENSION
- + WeightedResource.WEIGHT_PREFIX);
+ + WeightedResource.WEIGHT_PREFIX + ((htmlSuffix != null) ? WeightedResource.WEIGHT_METHOD : WeightedResource.WEIGHT_NONE));
return true;
}
if (scriptName.equals(suffix.substring(1))) {
addWeightedResource(resources, child, selIdx,
- WeightedResource.WEIGHT_EXTENSION);
+ WeightedResource.WEIGHT_EXTENSION + ((htmlSuffix != null) ? WeightedResource.WEIGHT_METHOD : WeightedResource.WEIGHT_NONE));
return true;
}
diff --git a/src/main/java/org/apache/sling/servlets/resolver/internal/helper/WeightedResource.java b/src/main/java/org/apache/sling/servlets/resolver/internal/helper/WeightedResource.java
index 470593f..a93a3e7 100644
--- a/src/main/java/org/apache/sling/servlets/resolver/internal/helper/WeightedResource.java
+++ b/src/main/java/org/apache/sling/servlets/resolver/internal/helper/WeightedResource.java
@@ -68,6 +68,12 @@ final class WeightedResource extends ResourceWrapper implements
*/
static final int WEIGHT_EXTENSION = 2;
+ /**
+ * Weight value added to method/prefix weight if the resource name contains
+ * the request method (value is 1).
+ */
+ static final int WEIGHT_METHOD = 1;
+
private final int ordinal;
private final int numSelectors;
diff --git a/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorTest.java b/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorTest.java
index b8e7611..317f0ce 100644
--- a/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorTest.java
+++ b/src/test/java/org/apache/sling/servlets/resolver/internal/helper/ResourceCollectorTest.java
@@ -19,6 +19,7 @@
package org.apache.sling.servlets.resolver.internal.helper;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -142,6 +143,18 @@ public class ResourceCollectorTest extends HelperTestBase {
effectiveTest(names, baseIdxs, indices);
}
+ public void testGetServletsWithMethod() {
+ String[] names = {
+ "/html.servlet", // 7
+ "/html.GET.servlet"
+ };
+
+ int[] baseIdxs = { 1, 1};
+ int[] indices = { 1, 0};
+
+ effectiveTest(names, baseIdxs, indices);
+ }
+
public void testGetServletsScriptExtensionsPriority() {
String[] names = {".servlet", // 0
"/" + label + ".esp", // 1