From ce1488309022ea9c1e9c7ac64c7f15a77b931ece Mon Sep 17 00:00:00 2001 From: shad0wm00n Date: Thu, 25 Dec 2025 00:06:26 +0800 Subject: [PATCH] =?UTF-8?q?fix=20issue=20IDFNF7=EF=BC=8C=E5=AF=B9=20StrMat?= =?UTF-8?q?cher=20=E5=A2=9E=E5=8A=A0=E6=A0=A1=E9=AA=8C=EF=BC=8C=E6=98=8E?= =?UTF-8?q?=E7=A1=AE=E7=A6=81=E6=AD=A2=E4=B8=8D=E5=B8=A6=E5=88=86=E9=9A=94?= =?UTF-8?q?=E7=AC=A6=E7=9A=84=E8=BF=9E=E7=BB=AD=E5=8F=98=E9=87=8F=EF=BC=88?= =?UTF-8?q?=E5=A6=82=20${a}${b}=EF=BC=89=EF=BC=8C=E4=BB=A5=E9=81=BF?= =?UTF-8?q?=E5=85=8D=E6=AD=A7=E4=B9=89=E8=A7=A3=E6=9E=90=E5=92=8C=E9=9D=99?= =?UTF-8?q?=E9=BB=98=E7=9A=84=E6=95=B0=E6=8D=AE=E4=B8=A2=E5=A4=B1=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/cn/hutool/core/text/StrMatcher.java | 5 +++++ .../java/cn/hutool/core/text/StrMatcherTest.java | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/hutool-core/src/main/java/cn/hutool/core/text/StrMatcher.java b/hutool-core/src/main/java/cn/hutool/core/text/StrMatcher.java index ccc59f87f9..3761cea4d6 100755 --- a/hutool-core/src/main/java/cn/hutool/core/text/StrMatcher.java +++ b/hutool-core/src/main/java/cn/hutool/core/text/StrMatcher.java @@ -46,6 +46,11 @@ public class StrMatcher { int to; for (String part : patterns) { if (StrUtil.isWrap(part, "${", "}")) { + // 禁止连续变量,例如${a}${b} + if (key != null) { + throw new IllegalArgumentException( + "Consecutive variables like ${a}${b} are not supported"); + } // 变量 key = StrUtil.sub(part, 2, part.length() - 1); } else { diff --git a/hutool-core/src/test/java/cn/hutool/core/text/StrMatcherTest.java b/hutool-core/src/test/java/cn/hutool/core/text/StrMatcherTest.java index 74aaf6f19c..76b436e4e3 100755 --- a/hutool-core/src/test/java/cn/hutool/core/text/StrMatcherTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/text/StrMatcherTest.java @@ -37,4 +37,17 @@ public class StrMatcherTest { assertEquals("小明", match.get("name")); assertEquals("20", match.get("year")); } + + @Test + public void issueIDFNF7Test() { + StrMatcher strMatcher = new StrMatcher("${a}${b}"); + + //final Map match = strMatcher.match("XY"); + //Console.log(match); // 此时会输出:"{b=XY}" + + assertThrows( + IllegalArgumentException.class, + () -> strMatcher.match("XY") + ); + } }