!1419 fix issue IDFNF7,对 StrMatcher 增加校验,明确禁止不带分隔符的连续变量(如 ${a}${b}),以避免歧义解析和静默的数据丢失问题。

Merge pull request !1419 from shad0wm00n/v5-dev-1224-3
This commit is contained in:
Looly
2025-12-27 03:49:37 +00:00
committed by Gitee
2 changed files with 18 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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<String, String> match = strMatcher.match("XY");
//Console.log(match); // 此时会输出:"{b=XY}"
assertThrows(
IllegalArgumentException.class,
() -> strMatcher.match("XY")
);
}
}