Skip to content

Commit

Permalink
Change max regex length in SpEL expressions to 1000
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sbrannen authored and bclozel committed Apr 13, 2023
1 parent ad19127 commit 18403cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = 256;
private static final int MAX_REGEX_LENGTH = 1000;

private final ConcurrentMap<String, Pattern> patternCache;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,24 @@ void matchesWithPatternAccessThreshold() {

@Test
void matchesWithPatternLengthThreshold() {
String pattern = "(0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
"0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" +
"01234567890123456789012345678901234567890123456789|abc)";
assertThat(pattern).hasSize(256);
Expression expr = parser.parseExpression("'abc' matches '" + pattern + "'");
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(257);
assertThat(pattern).hasSize(1001);
evaluateAndCheckError("'abc' matches '" + pattern + "'", Boolean.class, SpelMessage.MAX_REGEX_LENGTH_EXCEEDED);
}

private String repeat(String str, int count) {
String result = "";
for (int i = 0; i < count; i++) {
result += str;
}
return result;
}

// mixing operators
@Test
public void testMixingOperators01() {
Expand Down

0 comments on commit 18403cd

Please sign in to comment.