Author: kkolinko Date: Sun May 11 18:25:29 2014 New Revision: 1593836 URL: http://svn.apache.org/r1593836 Log: Correct the handling of back-slash escaping in the EL parser and no longer require that "\$" or "\#" must be followed by "{" in order for the back-slash escaping to take effect.
Modified: tomcat/tc6.0.x/trunk/ (props changed) tomcat/tc6.0.x/trunk/STATUS.txt tomcat/tc6.0.x/trunk/java/org/apache/el/parser/AstLiteralExpression.java tomcat/tc6.0.x/trunk/test/org/apache/el/TestELEvaluation.java tomcat/tc6.0.x/trunk/test/org/apache/jasper/compiler/TestELParser.java tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Propchange: tomcat/tc6.0.x/trunk/ ------------------------------------------------------------------------------ Merged /tomcat/trunk:r1590835,1590911,1593834 Merged /tomcat/tc7.0.x/trunk:r1590838,1590912,1593835 Modified: tomcat/tc6.0.x/trunk/STATUS.txt URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1593836&r1=1593835&r2=1593836&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/STATUS.txt (original) +++ tomcat/tc6.0.x/trunk/STATUS.txt Sun May 11 18:25:29 2014 @@ -28,14 +28,6 @@ None PATCHES PROPOSED TO BACKPORT: [ New proposals should be added at the end of the list ] -* Correct the handling of back-slash escaping in the EL parser and no longer - require that "\$" or "\#" must be followed by "{" in order for the back-slash - escaping to take effect. - http://svn.apache.org/r1590838 - http://svn.apache.org/r1590912 - +1: markt, kkolinko, fhanik - -1: - * Additional fixes for BZ 56334 http://svn.apache.org/r1590848 +1: kkolinko, markt, fhanik Modified: tomcat/tc6.0.x/trunk/java/org/apache/el/parser/AstLiteralExpression.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/el/parser/AstLiteralExpression.java?rev=1593836&r1=1593835&r2=1593836&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/el/parser/AstLiteralExpression.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/el/parser/AstLiteralExpression.java Sun May 11 18:25:29 2014 @@ -49,10 +49,9 @@ public final class AstLiteralExpression StringBuffer buf = new StringBuffer(size); for (int i = 0; i < size; i++) { char c = image.charAt(i); - if (c == '\\' && i + 2 < size) { + if (c == '\\' && i + 1 < size) { char c1 = image.charAt(i + 1); - char c2 = image.charAt(i + 2); - if ((c1 == '#' || c1 == '$') && c2 == '{') { + if (c1 == '#' || c1 == '$') { c = c1; i++; } Modified: tomcat/tc6.0.x/trunk/test/org/apache/el/TestELEvaluation.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/el/TestELEvaluation.java?rev=1593836&r1=1593835&r2=1593836&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/test/org/apache/el/TestELEvaluation.java (original) +++ tomcat/tc6.0.x/trunk/test/org/apache/el/TestELEvaluation.java Sun May 11 18:25:29 2014 @@ -73,8 +73,8 @@ public class TestELEvaluation extends Te assertEquals("many", evaluateExpression( "${0 lt 2 ? 1 lt 2 ? 'many': 'one': 'none'}")); } - - + + public void testParserBug45511() { // Test cases provided by OP assertEquals("true", evaluateExpression("${empty ('')}")); @@ -102,14 +102,21 @@ public class TestELEvaluation extends Te assertEquals("\\", evaluateExpression("\\")); assertEquals("$", evaluateExpression("$")); assertEquals("#", evaluateExpression("#")); - assertEquals("\\$", evaluateExpression("\\$")); - assertEquals("\\#", evaluateExpression("\\#")); - assertEquals("\\\\$", evaluateExpression("\\\\$")); - assertEquals("\\\\#", evaluateExpression("\\\\#")); + assertEquals("$", evaluateExpression("\\$")); + assertEquals("#", evaluateExpression("\\#")); + assertEquals("\\$", evaluateExpression("\\\\$")); + assertEquals("\\#", evaluateExpression("\\\\#")); assertEquals("${", evaluateExpression("\\${")); assertEquals("#{", evaluateExpression("\\#{")); assertEquals("\\${", evaluateExpression("\\\\${")); assertEquals("\\#{", evaluateExpression("\\\\#{")); + + // '\' is only an escape for '$' and '#'. + assertEquals("$", evaluateExpression("\\$")); + assertEquals("${", evaluateExpression("\\${")); + assertEquals("$a", evaluateExpression("\\$a")); + assertEquals("\\a", evaluateExpression("\\a")); + assertEquals("\\\\", evaluateExpression("\\\\")); } public void testParserStringLiteral() { @@ -171,6 +178,20 @@ public class TestELEvaluation extends Te assertTrue(null == null); } + /** + * Test mixing ${...} and #{...} in the same expression. + */ + public void testMixedTypes() { + // Mixing types should throw an error + Exception e = null; + try { + evaluateExpression("${1+1}#{1+1}"); + } catch (ELException el) { + e = el; + } + assertNotNull(e); + } + // ************************************************************************ private String evaluateExpression(String expression) { Modified: tomcat/tc6.0.x/trunk/test/org/apache/jasper/compiler/TestELParser.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/test/org/apache/jasper/compiler/TestELParser.java?rev=1593836&r1=1593835&r2=1593836&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/test/org/apache/jasper/compiler/TestELParser.java (original) +++ tomcat/tc6.0.x/trunk/test/org/apache/jasper/compiler/TestELParser.java Sun May 11 18:25:29 2014 @@ -232,13 +232,13 @@ public class TestELParser { @Test public void testEscape04() throws JasperException { - doTestParser("\\$", "\\$"); + doTestParser("\\$", "$"); } @Test public void testEscape05() throws JasperException { - doTestParser("\\#", "\\#"); + doTestParser("\\#", "#"); } Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=1593836&r1=1593835&r2=1593836&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Sun May 11 18:25:29 2014 @@ -163,6 +163,12 @@ <bug>56334</bug>: Fix a regression in the handling of back-slash escaping introduced by the fix for <bug>55735</bug>. (markt) </fix> + <fix> + Correct the handling of back-slash escaping in the EL parser and no + longer require that <code>\$</code> or <code>\#</code> must be followed + by <code>{</code> in order for the back-slash escaping to take effect. + (markt) + </fix> </changelog> </subsection> <subsection name="Cluster"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org