mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Increase max regex length in SpEL expressions
This commit increases the max regex length in SpEL expressions from 256 to 1024 in order to support use cases where a regex may be rather long without necessarily increasing the complexity of the regex. Closes gh-30265
This commit is contained in:
+4
-6
@@ -484,15 +484,13 @@ class EvaluationTests extends AbstractExpressionTests {
|
||||
|
||||
@Test
|
||||
void matchesWithPatternLengthThreshold() {
|
||||
String pattern = "(0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
|
||||
"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
|
||||
"01234567890123456789012345678901234567890123456789|abc)";
|
||||
assertThat(pattern).hasSize(256);
|
||||
Expression expr = parser.parseExpression("'abc' matches '" + pattern + "'");
|
||||
String pattern = "(%s|X)".formatted("1234".repeat(255));
|
||||
assertThat(pattern).hasSize(1024);
|
||||
Expression expr = parser.parseExpression("'X' matches '" + pattern + "'");
|
||||
assertThat(expr.getValue(context, Boolean.class)).isTrue();
|
||||
|
||||
pattern += "?";
|
||||
assertThat(pattern).hasSize(257);
|
||||
assertThat(pattern).hasSize(1025);
|
||||
evaluateAndCheckError("'abc' matches '" + pattern + "'", Boolean.class, SpelMessage.MAX_REGEX_LENGTH_EXCEEDED);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user