Support nested double quotes in SpEL expressions

The Spring Expression Language currently supports nested single quotes
within expressions but not nested double quotes.

The SpEL tokenizer has been modified to support nested double quotes in
the same way it supports single quotes. A sequence of two double quotes
will now be replaced by one when evaluated.

Extra error handling has also been added to report when invalid escaping
is encountered, since SpEL does not support escaping with backslash.

Issue: SPR-9620
This commit is contained in:
Andy Clement
2012-08-07 09:55:20 -07:00
committed by Sam Brannen
parent 0d963a690b
commit 75944cc88f
5 changed files with 32 additions and 4 deletions

View File

@@ -261,6 +261,25 @@ public class SpelParserTests {
assertEquals("ho", expr.getValue());
}
@Test
public void testStringLiterals_DoubleQuotes_spr9620() throws Exception {
SpelExpression expr = new SpelExpressionParser().parseRaw("\"double quote: \"\".\"");
assertEquals("double quote: \".", expr.getValue());
expr = new SpelExpressionParser().parseRaw("\"hello \"\" world\"");
assertEquals("hello \" world", expr.getValue());
}
@Test
public void testStringLiterals_DoubleQuotes_spr9620_2() throws Exception {
try {
new SpelExpressionParser().parseRaw("\"double quote: \\\"\\\".\"");
fail("Should have failed");
} catch (SpelParseException spe) {
assertEquals(17, spe.getPosition());
assertEquals(SpelMessage.UNEXPECTED_ESCAPE_CHAR, spe.getMessageCode());
}
}
@Test
public void positionalInformation() throws EvaluationException, ParseException {
SpelExpression expr = new SpelExpressionParser().parseRaw("true and true or false");