1
1
/*
2
- * Copyright 2002-2021 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.
30
30
*/
31
31
public class SpelParserConfiguration {
32
32
33
+ /**
34
+ * Default maximum length permitted for a SpEL expression.
35
+ * @since 5.2.24
36
+ */
37
+ private static final int DEFAULT_MAX_EXPRESSION_LENGTH = 10_000 ;
38
+
33
39
/** System property to configure the default compiler mode for SpEL expression parsers: {@value}. */
34
40
public static final String SPRING_EXPRESSION_COMPILER_MODE_PROPERTY_NAME = "spring.expression.compiler.mode" ;
35
41
@@ -54,6 +60,8 @@ public class SpelParserConfiguration {
54
60
55
61
private final int maximumAutoGrowSize ;
56
62
63
+ private final int maximumExpressionLength ;
64
+
57
65
58
66
/**
59
67
* Create a new {@code SpelParserConfiguration} instance with default settings.
@@ -102,11 +110,30 @@ public SpelParserConfiguration(boolean autoGrowNullReferences, boolean autoGrowC
102
110
public SpelParserConfiguration (@ Nullable SpelCompilerMode compilerMode , @ Nullable ClassLoader compilerClassLoader ,
103
111
boolean autoGrowNullReferences , boolean autoGrowCollections , int maximumAutoGrowSize ) {
104
112
113
+ this (compilerMode , compilerClassLoader , autoGrowNullReferences , autoGrowCollections ,
114
+ maximumAutoGrowSize , DEFAULT_MAX_EXPRESSION_LENGTH );
115
+ }
116
+
117
+ /**
118
+ * Create a new {@code SpelParserConfiguration} instance.
119
+ * @param compilerMode the compiler mode that parsers using this configuration object should use
120
+ * @param compilerClassLoader the ClassLoader to use as the basis for expression compilation
121
+ * @param autoGrowNullReferences if null references should automatically grow
122
+ * @param autoGrowCollections if collections should automatically grow
123
+ * @param maximumAutoGrowSize the maximum size that a collection can auto grow
124
+ * @param maximumExpressionLength the maximum length of a SpEL expression;
125
+ * must be a positive number
126
+ * @since 5.2.25
127
+ */
128
+ public SpelParserConfiguration (@ Nullable SpelCompilerMode compilerMode , @ Nullable ClassLoader compilerClassLoader ,
129
+ boolean autoGrowNullReferences , boolean autoGrowCollections , int maximumAutoGrowSize , int maximumExpressionLength ) {
130
+
105
131
this .compilerMode = (compilerMode != null ? compilerMode : defaultCompilerMode );
106
132
this .compilerClassLoader = compilerClassLoader ;
107
133
this .autoGrowNullReferences = autoGrowNullReferences ;
108
134
this .autoGrowCollections = autoGrowCollections ;
109
135
this .maximumAutoGrowSize = maximumAutoGrowSize ;
136
+ this .maximumExpressionLength = maximumExpressionLength ;
110
137
}
111
138
112
139
@@ -146,4 +173,12 @@ public int getMaximumAutoGrowSize() {
146
173
return this .maximumAutoGrowSize ;
147
174
}
148
175
176
+ /**
177
+ * Return the maximum number of characters that a SpEL expression can contain.
178
+ * @since 5.2.25
179
+ */
180
+ public int getMaximumExpressionLength () {
181
+ return this .maximumExpressionLength ;
182
+ }
183
+
149
184
}
0 commit comments