You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2020/04/09 13:11:15 UTC

[sling-org-apache-sling-servlets-resolver] branch issues/SLING-9348 created (now 686cfe2)

This is an automated email from the ASF dual-hosted git repository.

pauls pushed a change to branch issues/SLING-9348
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-resolver.git.


      at 686cfe2  SLING-9348: increase the weight for scripts with the method in their name.

This branch includes the following new commits:

     new 686cfe2  SLING-9348: increase the weight for scripts with the method in their name.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[sling-org-apache-sling-servlets-resolver] 01/01: SLING-9348: increase the weight for scripts with the method in their name.

Posted by pa...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

pauls pushed a commit to branch issues/SLING-9348
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-resolver.git

commit 686cfe242058d6adcdcb43e3f86796d6abf38ea9
Author: Karl Pauls <ka...@gmail.com>
AuthorDate: Thu Apr 9 15:10:55 2020 +0200

    SLING-9348: 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