You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/11/05 23:13:37 UTC
svn commit: r1539157 - in /tomcat/trunk:
java/org/apache/jasper/compiler/ELParser.java
test/org/apache/jasper/compiler/TestELParser.java
Author: markt
Date: Tue Nov 5 22:13:37 2013
New Revision: 1539157
URL: http://svn.apache.org/r1539157
Log:
Fix various bugs in Jasper's simplified EL parser and add the test case that found them.
This is a precursor to fixing BZ55198 / BZ55735 since that is going to require separating an attribute value into EL and non-EL components
Added:
tomcat/trunk/test/org/apache/jasper/compiler/TestELParser.java (with props)
Modified:
tomcat/trunk/java/org/apache/jasper/compiler/ELParser.java
Modified: tomcat/trunk/java/org/apache/jasper/compiler/ELParser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/ELParser.java?rev=1539157&r1=1539156&r2=1539157&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/ELParser.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/ELParser.java Tue Nov 5 22:13:37 2013
@@ -17,6 +17,12 @@
package org.apache.jasper.compiler;
+import org.apache.jasper.JasperException;
+import org.apache.jasper.compiler.ELNode.ELText;
+import org.apache.jasper.compiler.ELNode.Function;
+import org.apache.jasper.compiler.ELNode.Root;
+import org.apache.jasper.compiler.ELNode.Text;
+
/**
* This class implements a parser for EL expressions.
*
@@ -106,6 +112,7 @@ public class ELParser {
// Output whatever is in buffer
if (buf.length() > 0) {
ELexpr.add(new ELNode.ELText(buf.toString()));
+ buf = new StringBuilder();
}
if (!parseFunction()) {
ELexpr.add(new ELNode.ELText(curToken.toString()));
@@ -131,8 +138,8 @@ public class ELParser {
}
String s1 = null; // Function prefix
String s2 = curToken.toString(); // Function name
- int mark = getIndex();
if (hasNext()) {
+ int mark = getIndex();
curToken = nextToken();
if (curToken.toChar() == ':') {
if (hasNext()) {
@@ -150,8 +157,9 @@ public class ELParser {
ELexpr.add(new ELNode.Function(s1, s2));
return true;
}
+ curToken = prevToken;
+ setIndex(mark);
}
- setIndex(mark);
return false;
}
@@ -389,4 +397,42 @@ public class ELParser {
public char getType() {
return type;
}
+
+
+ protected static class TextBuilder extends ELNode.Visitor {
+
+ protected StringBuilder output = new StringBuilder();
+
+ public String getText() {
+ return output.toString();
+ }
+
+ @Override
+ public void visit(Root n) throws JasperException {
+ output.append(n.getType());
+ output.append('{');
+ n.getExpression().visit(this);
+ output.append('}');
+ }
+
+ @Override
+ public void visit(Function n) throws JasperException {
+ if (n.getPrefix() != null) {
+ output.append(n.getPrefix());
+ output.append(':');
+ }
+ output.append(n.getName());
+ output.append('(');
+ }
+
+ @Override
+ public void visit(Text n) throws JasperException {
+ output.append(n.getText());
+ }
+
+ @Override
+ public void visit(ELText n) throws JasperException {
+ output.append(n.getText());
+ }
+ }
}
Added: tomcat/trunk/test/org/apache/jasper/compiler/TestELParser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/compiler/TestELParser.java?rev=1539157&view=auto
==============================================================================
--- tomcat/trunk/test/org/apache/jasper/compiler/TestELParser.java (added)
+++ tomcat/trunk/test/org/apache/jasper/compiler/TestELParser.java Tue Nov 5 22:13:37 2013
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jasper.compiler;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.jasper.JasperException;
+import org.apache.jasper.compiler.ELNode.Nodes;
+import org.apache.jasper.compiler.ELParser.TextBuilder;
+
+public class TestELParser {
+
+ @Test
+ public void testText() throws JasperException {
+ doTestParser("foo");
+ }
+
+
+ @Test
+ public void testLiteral() throws JasperException {
+ doTestParser("${'foo'}");
+ }
+
+
+ @Test
+ public void testVariable() throws JasperException {
+ doTestParser("${test}");
+ }
+
+
+ @Test
+ public void testFunction01() throws JasperException {
+ doTestParser("${do(x)}");
+ }
+
+
+ @Test
+ public void testFunction02() throws JasperException {
+ doTestParser("${do:it(x)}");
+ }
+
+
+ @Test
+ public void testFunction03() throws JasperException {
+ doTestParser("${do:it(x,y)}");
+ }
+
+
+ @Test
+ public void testFunction04() throws JasperException {
+ doTestParser("${do:it(x,y,z)}");
+ }
+
+
+ @Test
+ public void testCompound01() throws JasperException {
+ doTestParser("1${'foo'}1");
+ }
+
+
+ @Test
+ public void testCompound02() throws JasperException {
+ doTestParser("1${test}1");
+ }
+
+
+ @Test
+ public void testCompound03() throws JasperException {
+ doTestParser("${foo}${bar}");
+ }
+
+
+ private void doTestParser(String input) throws JasperException {
+ Nodes nodes = ELParser.parse(input, false);
+
+ TextBuilder textBuilder = new TextBuilder();
+
+ nodes.visit(textBuilder);
+
+ Assert.assertEquals(input, textBuilder.getText());
+ }
+}
Propchange: tomcat/trunk/test/org/apache/jasper/compiler/TestELParser.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org