Skip to content

Commit cf727bd

Browse files
committed
Fix error message for invalid regex in SpEL
Closes gh-36756 (cherry picked from commit 987d6cc)
1 parent e8f08b4 commit cf727bd

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorMatches.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public BooleanTypedValue getValueInternal(ExpressionState state) throws Evaluati
117117

118118
private void checkRegexLength(String regex) {
119119
if (regex.length() > MAX_REGEX_LENGTH) {
120-
throw new SpelEvaluationException(getStartPosition(),
120+
throw new SpelEvaluationException(getRightOperand().getStartPosition(),
121121
SpelMessage.MAX_REGEX_LENGTH_EXCEEDED, MAX_REGEX_LENGTH);
122122
}
123123
}

spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ void matchesWithNullPattern() {
534534
void matchesWithPatternAccessThreshold() {
535535
String pattern = "^(?=[a-z0-9-]{1,47})([a-z0-9]+[-]{0,1}){1,47}[a-z0-9]{1}$";
536536
String expression = "'abcde-fghijklmn-o42pasdfasdfasdf.qrstuvwxyz10x.xx.yyy.zasdfasfd' matches '" + pattern + "'";
537-
evaluateAndCheckError(expression, SpelMessage.FLAWED_PATTERN);
537+
evaluateAndCheckError(expression, SpelMessage.FLAWED_PATTERN, 74);
538538
}
539539

540540
@Test
@@ -546,7 +546,7 @@ void matchesWithPatternLengthThreshold() {
546546

547547
pattern += "?";
548548
assertThat(pattern).hasSize(1001);
549-
evaluateAndCheckError("'X' matches '" + pattern + "'", Boolean.class, SpelMessage.MAX_REGEX_LENGTH_EXCEEDED);
549+
evaluateAndCheckError("'X' matches '" + pattern + "'", Boolean.class, SpelMessage.MAX_REGEX_LENGTH_EXCEEDED, 12);
550550
}
551551

552552
@Test

0 commit comments

Comments
 (0)