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

oxsean pushed a commit to branch 3.3
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.3 by this push:
     new 4853065a0a Fix #14778 (#14812)
4853065a0a is described below

commit 4853065a0a635b2bca7902ff071338a69cced339
Author: Sean Yang <[email protected]>
AuthorDate: Tue Oct 22 19:13:15 2024 +0800

    Fix #14778 (#14812)
---
 .../rpc/protocol/tri/rest/mapping/RadixTree.java      | 19 +++++++++----------
 .../protocol/tri/rest/mapping/RadixTreeTest.groovy    | 13 +++++++++++++
 2 files changed, 22 insertions(+), 10 deletions(-)

diff --git 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTree.java
 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTree.java
index 8e0b1ca238..1c57055986 100644
--- 
a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTree.java
+++ 
b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTree.java
@@ -184,15 +184,13 @@ public final class RadixTree<T> {
         int end = -2;
         if (!current.children.isEmpty()) {
             end = path.indexOf('/', start);
-            Node<T> node = current.children.get(path.subSequence(start, end));
-            if (node != null) {
+            Node<T> child = current.children.get(path.subSequence(start, end));
+            if (child != null) {
                 if (end == -1) {
-                    if (node.isLeaf()) {
-                        addMatch(node, variableMap, matches);
-                    }
-                    return;
+                    addMatch(child, variableMap, matches);
+                } else {
+                    matchRecursive(child, path, end + 1, variableMap, matches);
                 }
-                matchRecursive(node, path, end + 1, variableMap, matches);
             }
         }
 
@@ -212,9 +210,7 @@ public final class RadixTree<T> {
                     addMatch(child, workVariableMap, matches);
                 } else {
                     if (end == -1) {
-                        if (child.isLeaf()) {
-                            addMatch(child, workVariableMap, matches);
-                        }
+                        addMatch(child, workVariableMap, matches);
                     } else {
                         matchRecursive(child, path, end + 1, workVariableMap, 
matches);
                     }
@@ -228,6 +224,9 @@ public final class RadixTree<T> {
 
     private static <T> void addMatch(Node<T> node, Map<String, String> 
variableMap, List<Match<T>> matches) {
         List<Pair<PathExpression, T>> values = node.values;
+        if (values.isEmpty()) {
+            return;
+        }
         variableMap = variableMap.isEmpty() ? Collections.emptyMap() : 
Collections.unmodifiableMap(variableMap);
         for (int i = 0, size = values.size(); i < size; i++) {
             Pair<PathExpression, T> pair = values.get(i);
diff --git 
a/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTreeTest.groovy
 
b/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTreeTest.groovy
index b40080486d..4966e7b7ab 100644
--- 
a/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTreeTest.groovy
+++ 
b/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/mapping/RadixTreeTest.groovy
@@ -58,4 +58,17 @@ class RadixTreeTest extends Specification {
             '/a/b/c'   | 1
             '/a/b/c/d' | 0
     }
+
+    def "test sub path match"() {
+        given:
+            def tree = new RadixTree<String>();
+            tree.addPath("/update/{ruleId}", "a")
+            tree.addPath("/update/{ruleId}/state", "b")
+        expect:
+            tree.match(path).first.value == result
+        where:
+            path                    | result
+            '/update/1222222'       | 'a'
+            '/update/1222222/state' | 'b'
+    }
 }

Reply via email to