diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorMatches.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorMatches.java index 1775309b153e..de277c68eaf6 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorMatches.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorMatches.java @@ -47,7 +47,7 @@ public class OperatorMatches extends Operator { * Maximum number of characters permitted in a regular expression. * @since 5.2.23 */ - private static final int MAX_REGEX_LENGTH = 1024; + private static final int MAX_REGEX_LENGTH = 1000; private final ConcurrentMap patternCache; diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java index 6b246560e0eb..908af596cf4b 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java @@ -482,13 +482,13 @@ void matchesWithPatternAccessThreshold() { @Test void matchesWithPatternLengthThreshold() { - String pattern = String.format("(%s|X)", repeat("1234", 255)); - assertThat(pattern).hasSize(1024); + String pattern = String.format("^(%s|X)", repeat("12345", 199)); + assertThat(pattern).hasSize(1000); Expression expr = parser.parseExpression("'X' matches '" + pattern + "'"); assertThat(expr.getValue(context, Boolean.class)).isTrue(); pattern += "?"; - assertThat(pattern).hasSize(1025); + assertThat(pattern).hasSize(1001); evaluateAndCheckError("'abc' matches '" + pattern + "'", Boolean.class, SpelMessage.MAX_REGEX_LENGTH_EXCEEDED); }