From 2658708e030f46d4aa10da60919fced2e4f8966e Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Fri, 3 Aug 2012 10:41:19 -0700 Subject: [PATCH] Case insensitive null literals supported. Prior to this change null literals had to be specified as "null", with this change the check is now case insensitive. Issue: SPR-9613 --- .../standard/InternalSpelExpressionParser.java | 2 +- .../expression/spel/EvaluationTests.java | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java index ec43b2bfab74..84c3c2735002 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java @@ -513,7 +513,7 @@ private boolean maybeEatTypeReference() { private boolean maybeEatNullReference() { if (peekToken(TokenKind.IDENTIFIER)) { Token nullToken = peekToken(); - if (!nullToken.stringValue().equals("null")) { + if (!nullToken.stringValue().toLowerCase().equals("null")) { return false; } nextToken(); diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java index bb50bfeb0bd0..f4b1c4458b5e 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2012 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. @@ -32,6 +32,7 @@ import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.support.StandardTypeLocator; import org.springframework.expression.spel.testresources.TestPerson; +import static org.junit.Assert.assertNull; /** * Tests the evaluation of real expressions in a real context. @@ -558,4 +559,16 @@ public void initializingCollectionElementsOnWrite() throws Exception { Assert.assertEquals("Wibble",person.getAddress().getCrossStreets().get(3)); } + @Test + public void uppercaseNullLiteral_spr9613() { + ExpressionParser parser = new SpelExpressionParser(); + Expression exp = parser.parseExpression("null"); + Object result = exp.getValue(); + assertNull(result); + + exp = parser.parseExpression("NULL"); + result = exp.getValue(); + assertNull(result); + } + }