Fix for a bug with processing of double quotes in AttributeParser#parseEL()
authorkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 4 Feb 2010 12:18:28 +0000 (12:18 +0000)
committerkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Thu, 4 Feb 2010 12:18:28 +0000 (12:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@906465 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/jasper/compiler/AttributeParser.java
test/org/apache/jasper/compiler/TestAttributeParser.java

index 629be7b..c19fac7 100644 (file)
@@ -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) {
index 3e806e6..42e0d87 100644 (file)
@@ -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(