From be129dc17160c82da9e56b88321da13199cda2af Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Tue, 11 Apr 2023 23:08:53 +0200 Subject: [PATCH] Change max regex length in SpEL expressions to 1000 This commit changes the max regex length in SpEL expressions from 1024 to 1000 in order to consistently use "round" numbers for recently introduced limits. See gh-30265 --- .../expression/spel/ast/OperatorMatches.java | 2 +- .../springframework/expression/spel/EvaluationTests.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) 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); }