From 7b0770dcbe973a1b46614b247a4a505fa668f0bf Mon Sep 17 00:00:00 2001 From: kkolinko Date: Thu, 4 Feb 2010 12:18:28 +0000 Subject: [PATCH] Fix for a bug with processing of double quotes in AttributeParser#parseEL() git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@906465 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/jasper/compiler/AttributeParser.java | 2 +- .../org/apache/jasper/compiler/TestAttributeParser.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/java/org/apache/jasper/compiler/AttributeParser.java b/java/org/apache/jasper/compiler/AttributeParser.java index 629be7baf..c19fac7ba 100644 --- a/java/org/apache/jasper/compiler/AttributeParser.java +++ b/java/org/apache/jasper/compiler/AttributeParser.java @@ -214,8 +214,8 @@ public class AttributeParser { private void parseEL() { boolean endEL = false; boolean insideLiteral = false; + char literalQuote = 0; while (i < size && !endEL) { - char literalQuote = '\''; char ch = nextChar(); if (ch == '\'' || ch == '\"') { if (insideLiteral) { diff --git a/test/org/apache/jasper/compiler/TestAttributeParser.java b/test/org/apache/jasper/compiler/TestAttributeParser.java index 3e806e658..42e0d87d3 100644 --- a/test/org/apache/jasper/compiler/TestAttributeParser.java +++ b/test/org/apache/jasper/compiler/TestAttributeParser.java @@ -135,9 +135,24 @@ public class TestAttributeParser extends TestCase { // Quoting <% and %> assertEquals("hello <% world", evalAttr("hello <\\% world", '\"')); assertEquals("hello %> world", evalAttr("hello %> world", '\"')); + + // Test that the end of literal in EL expression is recognized in + // parseEL(), be it quoted with single or double quotes. That is, that + // AttributeParser correctly switches between parseLiteral and parseEL + // methods. + // + // The test is based on the difference in how the '\' character is printed: + // when in parseLiteral \\${ will be printed as ${'\'}${, but if we are still + // inside of parseEL it will be printed as \${, thus preventing the EL + // expression that follows from being evaluated. + // + assertEquals("foo\\bar\\baz", evalAttr("${\'foo\'}\\\\${\'bar\'}\\\\${\'baz\'}", '\"')); + assertEquals("foo\\bar\\baz", evalAttr("${\'foo\'}\\\\${\\\"bar\\\"}\\\\${\'baz\'}", '\"')); + assertEquals("foo\\bar\\baz", evalAttr("${\\\"foo\\\"}\\\\${\'bar\'}\\\\${\\\"baz\\\"}", '\"')); + assertEquals("foo\\bar\\baz", evalAttr("${\"foo\"}\\\\${\\\'bar\\\'}\\\\${\"baz\"}", '\'')); } - public void testScriptExpressiinLiterals() { + public void testScriptExpressionLiterals() { assertEquals(" \"hello world\" ", parseScriptExpression( " \"hello world\" ", (char) 0)); assertEquals(" \"hello \\\"world\" ", parseScriptExpression( -- 2.11.0