Skip to content

Commit be129dc

Browse files
sbrannenbclozel
authored andcommitted
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
1 parent 8bb1b3e commit be129dc

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class OperatorMatches extends Operator {
4747
* Maximum number of characters permitted in a regular expression.
4848
* @since 5.2.23
4949
*/
50-
private static final int MAX_REGEX_LENGTH = 1024;
50+
private static final int MAX_REGEX_LENGTH = 1000;
5151

5252
private final ConcurrentMap<String, Pattern> patternCache;
5353

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,13 @@ void matchesWithPatternAccessThreshold() {
482482

483483
@Test
484484
void matchesWithPatternLengthThreshold() {
485-
String pattern = String.format("(%s|X)", repeat("1234", 255));
486-
assertThat(pattern).hasSize(1024);
485+
String pattern = String.format("^(%s|X)", repeat("12345", 199));
486+
assertThat(pattern).hasSize(1000);
487487
Expression expr = parser.parseExpression("'X' matches '" + pattern + "'");
488488
assertThat(expr.getValue(context, Boolean.class)).isTrue();
489489

490490
pattern += "?";
491-
assertThat(pattern).hasSize(1025);
491+
assertThat(pattern).hasSize(1001);
492492
evaluateAndCheckError("'abc' matches '" + pattern + "'", Boolean.class, SpelMessage.MAX_REGEX_LENGTH_EXCEEDED);
493493
}
494494

0 commit comments

Comments
 (0)