Skip to content

Commit 18403cd

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 ad19127 commit 18403cd

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
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 = 256;
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

+12-6
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,24 @@ void matchesWithPatternAccessThreshold() {
201201

202202
@Test
203203
void matchesWithPatternLengthThreshold() {
204-
String pattern = "(0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
205-
"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
206-
"01234567890123456789012345678901234567890123456789|abc)";
207-
assertThat(pattern).hasSize(256);
208-
Expression expr = parser.parseExpression("'abc' matches '" + pattern + "'");
204+
String pattern = String.format("^(%s|X)", repeat("12345", 199));
205+
assertThat(pattern).hasSize(1000);
206+
Expression expr = parser.parseExpression("'X' matches '" + pattern + "'");
209207
assertThat(expr.getValue(context, Boolean.class)).isTrue();
210208

211209
pattern += "?";
212-
assertThat(pattern).hasSize(257);
210+
assertThat(pattern).hasSize(1001);
213211
evaluateAndCheckError("'abc' matches '" + pattern + "'", Boolean.class, SpelMessage.MAX_REGEX_LENGTH_EXCEEDED);
214212
}
215213

214+
private String repeat(String str, int count) {
215+
String result = "";
216+
for (int i = 0; i < count; i++) {
217+
result += str;
218+
}
219+
return result;
220+
}
221+
216222
// mixing operators
217223
@Test
218224
public void testMixingOperators01() {

0 commit comments

Comments
 (0)