From 60c815ab76306c6edf1e1f8511b14c168761a9c9 Mon Sep 17 00:00:00 2001 From: JuJu <857815116@qq.com> Date: Sun, 28 Feb 2021 17:21:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=96=B9=E6=B3=95=E8=BF=87=E6=BB=A4=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E4=B8=8E=E5=8D=95*=E5=8C=B9=E9=85=8D=E4=B8=8D=E7=B2=BE?= =?UTF-8?q?=E7=A1=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/common/core/utils/StringUtils.java | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) 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)