Browse Source

Reintroduce support for null SpEL expressions

Closes gh-30464
5.2.x
Sam Brannen 3 years ago
parent
commit
89a3d64ada
  1. 2
      spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java
  2. 14
      spring-expression/src/test/java/org/springframework/expression/spel/standard/SpelParserTests.java

2
spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java

@ -158,7 +158,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { @@ -158,7 +158,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
}
private void checkExpressionLength(String string) {
if (string.length() > MAX_EXPRESSION_LENGTH) {
if (string != null && string.length() > MAX_EXPRESSION_LENGTH) {
throw new SpelEvaluationException(SpelMessage.MAX_EXPRESSION_LENGTH_EXCEEDED, MAX_EXPRESSION_LENGTH);
}
}

14
spring-expression/src/test/java/org/springframework/expression/spel/standard/SpelParserTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -21,7 +21,9 @@ import java.util.function.Consumer; @@ -21,7 +21,9 @@ import java.util.function.Consumer;
import org.junit.jupiter.api.Test;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionException;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.SpelMessage;
import org.springframework.expression.spel.SpelNode;
import org.springframework.expression.spel.SpelParseException;
@ -35,9 +37,19 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -35,9 +37,19 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
* @author Andy Clement
* @author Juergen Hoeller
* @author Sam Brannen
*/
public class SpelParserTests {
@Test // gh-30464
public void nullExpression() {
ExpressionParser parser = new SpelExpressionParser();
String expression = null;
Expression expr = parser.parseExpression(expression);
Object result = expr.getValue();
assertThat(result).isNull();
}
@Test
public void theMostBasic() {
SpelExpressionParser parser = new SpelExpressionParser();

Loading…
Cancel
Save