Skip to content

Commit

Permalink
Reintroduce support for null SpEL expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen authored and lakeslove committed Dec 28, 2024
1 parent 355ca54 commit 3f2ea47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected SpelExpression doParseExpression(String expressionString, @Nullable Pa
}

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);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -21,7 +21,9 @@
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;
Expand All @@ -35,9 +37,19 @@
/**
* @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();
Expand Down

0 comments on commit 3f2ea47

Please sign in to comment.