This is an automated email from the ASF dual-hosted git repository.
likeguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 85fec706b [type:fix] fix trie match error (#4504)
85fec706b is described below
commit 85fec706bba7c8cb5bd2991fd3fac2db8ca7867e
Author: moremind <[email protected]>
AuthorDate: Mon Mar 27 15:44:52 2023 +0800
[type:fix] fix trie match error (#4504)
* [type:fix] fix trie match error
* [type:fix] fix trie match error
---
.../common/cache/MemorySafeWindowTinyLFUMapTest.java | 1 +
.../org/apache/shenyu/plugin/base/trie/ShenyuTrie.java | 15 +++++++++------
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git
a/shenyu-common/src/test/java/org/apache/shenyu/common/cache/MemorySafeWindowTinyLFUMapTest.java
b/shenyu-common/src/test/java/org/apache/shenyu/common/cache/MemorySafeWindowTinyLFUMapTest.java
index c7fc367f9..38f20a2f6 100644
---
a/shenyu-common/src/test/java/org/apache/shenyu/common/cache/MemorySafeWindowTinyLFUMapTest.java
+++
b/shenyu-common/src/test/java/org/apache/shenyu/common/cache/MemorySafeWindowTinyLFUMapTest.java
@@ -53,6 +53,7 @@ public class MemorySafeWindowTinyLFUMapTest {
Assert.assertEquals(1, cache.size());
cache.put(2, 2);
cache.put(3, 3);
+ cache.invalidate();
cache.cleanUp();
Assert.assertEquals(1, cache.size());
final Map.Entry<Integer, Integer> entry =
cache.entrySet().iterator().next();
diff --git
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java
index 9e0093403..13e47002a 100644
---
a/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java
+++
b/shenyu-plugin/shenyu-plugin-base/src/main/java/org/apache/shenyu/plugin/base/trie/ShenyuTrie.java
@@ -228,9 +228,9 @@ public class ShenyuTrie {
ShenyuTrieNode currentNode = root;
for (int i = 0; i < pathParts.length; i++) {
String path = pathParts[i];
- currentNode = matchNode(path, currentNode, selectorId);
+ boolean endPath = judgeEqual(i, pathParts.length - 1);
+ currentNode = matchNode(path, currentNode, selectorId,
endPath, pathParts[pathParts.length - 1]);
if (Objects.nonNull(currentNode)) {
- boolean endPath = judgeEqual(i, pathParts.length - 1);
// path is not end, continue to execute
if (checkChildrenNotNull(currentNode) &&
!currentNode.getEndOfPath()) {
continue;
@@ -264,11 +264,12 @@ public class ShenyuTrie {
* @param selectorId selectorId
* @return {@linkplain ShenyuTrieNode}
*/
- private ShenyuTrieNode matchNode(final String segment, final
ShenyuTrieNode node, final String selectorId) {
+ private ShenyuTrieNode matchNode(final String segment, final
ShenyuTrieNode node, final String selectorId,
+ final Boolean endOfPath, final String
lastSegment) {
if (Objects.nonNull(node)) {
// node exist in children,first find path, avoid A plug have
/http/**, B plug have /http/order/**
if (checkChildrenNotNull(node)) {
- Pair<Boolean, ShenyuTrieNode> pair = filterTrieNode(node,
selectorId);
+ Pair<Boolean, ShenyuTrieNode> pair = filterTrieNode(node,
selectorId, endOfPath, lastSegment);
if (pair.getLeft()) {
return pair.getRight();
}
@@ -363,10 +364,12 @@ public class ShenyuTrie {
return null;
}
- private Pair<Boolean, ShenyuTrieNode> filterTrieNode(final ShenyuTrieNode
node, final String selectorId) {
+ private Pair<Boolean, ShenyuTrieNode> filterTrieNode(final ShenyuTrieNode
node, final String selectorId,
+ final boolean
endOfPath, final String lastSegment) {
Map<String, ShenyuTrieNode> currentMap = node.getChildren();
List<ShenyuTrieNode> filterTrieNodes = currentMap.values().stream()
- .filter(currentNode -> currentNode.getEndOfPath() &&
selectorId.equals(currentNode.getSelectorId()))
+ .filter(currentNode -> currentNode.getEndOfPath() &&
selectorId.equals(currentNode.getSelectorId())
+ && (isMatchAllOrWildcard(currentNode.getMatchStr()) ||
(endOfPath && lastSegment.equals(currentNode.getMatchStr()))))
.collect(Collectors.toList());
if (filterTrieNodes.size() != 1) {
return Pair.of(Boolean.FALSE, null);