diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java index b1501699..954dd03e 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/StringUtils.java @@ -21,6 +21,9 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils /** 星号 */ private static final String START = "*"; + /** 斜杠 */ + private static final String SLASH = "/"; + /** * 获取参数不为空值 * @@ -477,22 +480,27 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils // 匹配前缀Pattern result = remainingURI.contains(prefixPattern); + + // 匹配失败,直接返回 + if (!result) + return false; + // 已经没有星号,判断长度是否符合,并返回 if (formerStarOffset == -1) { - //清洗请求路径 - if (remainingURI.endsWith("/")) { + // 清洗请求路径 + if (remainingURI.endsWith(SLASH)) { remainingURI = remainingURI.substring(0, remainingURI.length() - 1); } return remainingURI.length() == prefixPattern.length(); } - // 匹配失败,直接返回 - if (!result) - return false; - if (!isEmpty(prefixPattern)) { + // 如果前面还有路径 直接返回 + if (!isEmpty(substringBefore(str, prefixPattern))) { + return false; + } remainingURI = substringAfter(str, prefixPattern); } @@ -500,6 +508,14 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils latterStarOffset = indexOf(pattern, START, formerStarOffset + 1); suffixPattern = substring(pattern, formerStarOffset + 1, latterStarOffset > -1 ? latterStarOffset : pattern.length()); + // 判断是否存在第二个 * + if (latterStarOffset == -1) { + // 判断是否还包含斜杠 + if(remainingURI.contains(SLASH)) { + return false; + } + } + result = remainingURI.contains(suffixPattern); // 匹配失败,直接返回 if (!result)