You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2010/02/04 13:18:29 UTC

svn commit: r906465 - in /tomcat/trunk: java/org/apache/jasper/compiler/AttributeParser.java test/org/apache/jasper/compiler/TestAttributeParser.java

Author: kkolinko
Date: Thu Feb  4 12:18:28 2010
New Revision: 906465

URL: http://svn.apache.org/viewvc?rev=906465&view=rev
Log:
Fix for a bug with processing of double quotes in AttributeParser#parseEL()

Modified:
    tomcat/trunk/java/org/apache/jasper/compiler/AttributeParser.java
    tomcat/trunk/test/org/apache/jasper/compiler/TestAttributeParser.java

Modified: tomcat/trunk/java/org/apache/jasper/compiler/AttributeParser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/AttributeParser.java?rev=906465&r1=906464&r2=906465&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/AttributeParser.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/AttributeParser.java Thu Feb  4 12:18:28 2010
@@ -214,8 +214,8 @@
     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) {

Modified: tomcat/trunk/test/org/apache/jasper/compiler/TestAttributeParser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/compiler/TestAttributeParser.java?rev=906465&r1=906464&r2=906465&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/jasper/compiler/TestAttributeParser.java (original)
+++ tomcat/trunk/test/org/apache/jasper/compiler/TestAttributeParser.java Thu Feb  4 12:18:28 2010
@@ -135,9 +135,24 @@
         // 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(



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org