1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
25
25
* @author Juergen Hoeller
26
26
* @author Phillip Webb
27
27
* @author Andy Clement
28
+ * @author Sam Brannen
28
29
* @since 3.0
29
30
* @see org.springframework.expression.spel.standard.SpelExpressionParser#SpelExpressionParser(SpelParserConfiguration)
30
31
*/
31
32
public class SpelParserConfiguration {
32
33
34
+ /**
35
+ * Default maximum length permitted for a SpEL expression.
36
+ * @since 5.2.24
37
+ */
38
+ private static final int DEFAULT_MAX_EXPRESSION_LENGTH = 10_000 ;
39
+
40
+
33
41
private static final SpelCompilerMode defaultCompilerMode ;
34
42
35
43
static {
@@ -50,6 +58,8 @@ public class SpelParserConfiguration {
50
58
51
59
private final int maximumAutoGrowSize ;
52
60
61
+ private final int maximumExpressionLength ;
62
+
53
63
54
64
/**
55
65
* Create a new {@code SpelParserConfiguration} instance with default settings.
@@ -98,11 +108,30 @@ public SpelParserConfiguration(boolean autoGrowNullReferences, boolean autoGrowC
98
108
public SpelParserConfiguration (@ Nullable SpelCompilerMode compilerMode , @ Nullable ClassLoader compilerClassLoader ,
99
109
boolean autoGrowNullReferences , boolean autoGrowCollections , int maximumAutoGrowSize ) {
100
110
111
+ this (compilerMode , compilerClassLoader , autoGrowNullReferences , autoGrowCollections ,
112
+ maximumAutoGrowSize , DEFAULT_MAX_EXPRESSION_LENGTH );
113
+ }
114
+
115
+ /**
116
+ * Create a new {@code SpelParserConfiguration} instance.
117
+ * @param compilerMode the compiler mode that parsers using this configuration object should use
118
+ * @param compilerClassLoader the ClassLoader to use as the basis for expression compilation
119
+ * @param autoGrowNullReferences if null references should automatically grow
120
+ * @param autoGrowCollections if collections should automatically grow
121
+ * @param maximumAutoGrowSize the maximum size that a collection can auto grow
122
+ * @param maximumExpressionLength the maximum length of a SpEL expression;
123
+ * must be a positive number
124
+ * @since 5.2.25
125
+ */
126
+ public SpelParserConfiguration (@ Nullable SpelCompilerMode compilerMode , @ Nullable ClassLoader compilerClassLoader ,
127
+ boolean autoGrowNullReferences , boolean autoGrowCollections , int maximumAutoGrowSize , int maximumExpressionLength ) {
128
+
101
129
this .compilerMode = (compilerMode != null ? compilerMode : defaultCompilerMode );
102
130
this .compilerClassLoader = compilerClassLoader ;
103
131
this .autoGrowNullReferences = autoGrowNullReferences ;
104
132
this .autoGrowCollections = autoGrowCollections ;
105
133
this .maximumAutoGrowSize = maximumAutoGrowSize ;
134
+ this .maximumExpressionLength = maximumExpressionLength ;
106
135
}
107
136
108
137
@@ -142,4 +171,12 @@ public int getMaximumAutoGrowSize() {
142
171
return this .maximumAutoGrowSize ;
143
172
}
144
173
174
+ /**
175
+ * Return the maximum number of characters that a SpEL expression can contain.
176
+ * @since 5.2.25
177
+ */
178
+ public int getMaximumExpressionLength () {
179
+ return this .maximumExpressionLength ;
180
+ }
181
+
145
182
}
0 commit comments