Author: markt Date: Fri Jul 5 16:33:06 2013 New Revision: 1500062 URL: http://svn.apache.org/r1500062 Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=55198 ELInterpreter needs to know if page was originally in XML
Added: tomcat/trunk/test/webapp/WEB-INF/tags/bug55198.tagx tomcat/trunk/test/webapp/bug5nnnn/bug55198.jsp (with props) Modified: tomcat/trunk/java/org/apache/jasper/compiler/Generator.java tomcat/trunk/test/org/apache/jasper/compiler/TestParser.java Modified: tomcat/trunk/java/org/apache/jasper/compiler/Generator.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/Generator.java?rev=1500062&r1=1500061&r2=1500062&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/jasper/compiler/Generator.java (original) +++ tomcat/trunk/java/org/apache/jasper/compiler/Generator.java Fri Jul 5 16:33:06 2013 @@ -820,7 +820,7 @@ class Generator { * attributes that aren't EL expressions) */ private String attributeValue(Node.JspAttribute attr, boolean encode, - Class<?> expectedType) { + Class<?> expectedType, boolean isXml) { String v = attr.getValue(); if (!attr.isNamedAttribute() && (v == null)) return ""; @@ -833,7 +833,7 @@ class Generator { return v; } else if (attr.isELInterpreterInput()) { v = elInterpreter.interpreterCall(ctxt, this.isTagFile, v, - expectedType, attr.getEL().getMapName(), false); + expectedType, attr.getEL().getMapName(), isXml); if (encode) { return "org.apache.jasper.runtime.JspRuntimeLibrary.URLEncode(" + v + ", request.getCharacterEncoding())"; @@ -878,7 +878,8 @@ class Generator { + "URLEncode(" + quote(n.getTextAttribute("name")) + ", request.getCharacterEncoding())"); out.print("+ \"=\" + "); - out.print(attributeValue(n.getValue(), true, String.class)); + out.print(attributeValue(n.getValue(), true, String.class, + n.getRoot().isXmlSyntax())); // The separator is '&' after the second use separator = "\"&\""; @@ -949,7 +950,8 @@ class Generator { pageParam = generateNamedAttributeValue(page .getNamedAttributeNode()); } else { - pageParam = attributeValue(page, false, String.class); + pageParam = attributeValue(page, false, String.class, + n.getRoot().isXmlSyntax()); } // If any of the params have their values specified by @@ -1035,7 +1037,8 @@ class Generator { pageParam = generateNamedAttributeValue(page .getNamedAttributeNode()); } else { - pageParam = attributeValue(page, false, String.class); + pageParam = attributeValue(page, false, String.class, + n.getRoot().isXmlSyntax()); } // If any of the params have their values specified by @@ -1142,7 +1145,8 @@ class Generator { + "_jspx_page_context.findAttribute(\"" + name + "\"), \"" + property + "\","); - out.print(attributeValue(value, false, null)); + out.print(attributeValue(value, false, null, + n.getRoot().isXmlSyntax())); out.println(");"); } else if (value.isELInterpreterInput()) { // We've got to resolve the very call to the interpreter @@ -1187,7 +1191,8 @@ class Generator { + "_jspx_page_context.findAttribute(\"" + name + "\"), \"" + property + "\", "); - out.print(attributeValue(value, false, null)); + out.print(attributeValue(value, false, null, + n.getRoot().isXmlSyntax())); out.println(", null, null, false);"); } @@ -1319,7 +1324,7 @@ class Generator { .getNamedAttributeNode()); } else { binaryName = attributeValue(beanName, false, - String.class); + String.class, n.getRoot().isXmlSyntax()); } } else { // Implies klass is not null @@ -1428,20 +1433,24 @@ class Generator { // We want something of the form // out.println( "<param name=\"blah\" // value=\"" + ... + "\">" ); - out.printil("out.write( \"<param name=\\\"" - + escape(name) - + "\\\" value=\\\"\" + " - + attributeValue(n.getValue(), false, - String.class) + " + \"\\\">\" );"); + out.printil("out.write( \"<param name=\\\"" + + escape(name) + + "\\\" value=\\\"\" + " + + attributeValue(n.getValue(), false, + String.class, + n.getRoot().isXmlSyntax()) + + " + \"\\\">\" );"); out.printil("out.write(\"\\n\");"); } else { // We want something of the form // out.print( " blah=\"" + ... + "\"" ); - out.printil("out.write( \" " - + escape(name) - + "=\\\"\" + " - + attributeValue(n.getValue(), false, - String.class) + " + \"\\\"\" );"); + out.printil("out.write( \" " + + escape(name) + + "=\\\"\" + " + + attributeValue(n.getValue(), false, + String.class, + n.getRoot().isXmlSyntax()) + + " + \"\\\"\" );"); } n.setEndJavaLine(out.getJavaLine()); @@ -1468,7 +1477,8 @@ class Generator { widthStr = generateNamedAttributeValue(width .getNamedAttributeNode()); } else { - widthStr = attributeValue(width, false, String.class); + widthStr = attributeValue(width, false, String.class, + n.getRoot().isXmlSyntax()); } } @@ -1478,7 +1488,8 @@ class Generator { heightStr = generateNamedAttributeValue(height .getNamedAttributeNode()); } else { - heightStr = attributeValue(height, false, String.class); + heightStr = attributeValue(height, false, String.class, + n.getRoot().isXmlSyntax()); } } @@ -1833,8 +1844,9 @@ class Generator { out.print("="); if (jspAttrs[i].isELInterpreterInput()) { out.print("\\\"\" + "); - out.print(attributeValue(jspAttrs[i], false, - String.class)); + String debug = attributeValue(jspAttrs[i], false, + String.class, n.getRoot().isXmlSyntax()); + out.print(debug); out.print(" + \"\\\""); } else { out.print(DOUBLE_QUOTE); @@ -1882,7 +1894,8 @@ class Generator { if (omitAttr == null) { omit = "false"; } else { - omit = attributeValue(omitAttr, false, boolean.class); + omit = attributeValue(omitAttr, false, boolean.class, + n.getRoot().isXmlSyntax()); if ("true".equals(omit)) { continue; } @@ -1898,7 +1911,8 @@ class Generator { " + \"\\\"\")"; } } else { - value = attributeValue(attrs[i], false, Object.class); + value = attributeValue(attrs[i], false, Object.class, + n.getRoot().isXmlSyntax()); nvp = " + \" " + attrs[i].getName() + "=\\\"\" + " + value + " + \"\\\"\""; } @@ -1908,7 +1922,7 @@ class Generator { // Write begin tag, using XML-style 'name' attribute as the // element name String elemName = attributeValue(n.getNameAttribute(), false, - String.class); + String.class, n.getRoot().isXmlSyntax()); out.printin("out.write(\"<\""); out.print(" + " + elemName); Modified: tomcat/trunk/test/org/apache/jasper/compiler/TestParser.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/compiler/TestParser.java?rev=1500062&r1=1500061&r2=1500062&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/jasper/compiler/TestParser.java (original) +++ tomcat/trunk/test/org/apache/jasper/compiler/TestParser.java Fri Jul 5 16:33:06 2013 @@ -24,6 +24,7 @@ import java.util.List; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import org.junit.Assert; import org.junit.Test; import org.apache.catalina.startup.Tomcat; @@ -312,6 +313,28 @@ public class TestParser extends TomcatBa assertEcho(result, "02 - <p>Foo</p><%"); } + @Test + public void testBug55198() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File appDir = new File("test/webapp"); + // app dir is relative to server home + tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); + + tomcat.start(); + + ByteChunk res = getUrl("http://localhost:" + getPort() + + "/test/bug5nnnn/bug55198.jsp"); + + String result = res.toString(); + + System.out.println(result); + Assert.assertTrue(result.contains(""bar"") || + result.contains(""bar"")); + Assert.assertTrue(result.contains(""foo"") || + result.contains(""foo"")); + } + /** Assertion for text printed by tags:echo */ private static void assertEcho(String result, String expected) { assertTrue(result.indexOf("<p>" + expected + "</p>") > 0); Added: tomcat/trunk/test/webapp/WEB-INF/tags/bug55198.tagx URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/WEB-INF/tags/bug55198.tagx?rev=1500062&view=auto ============================================================================== --- tomcat/trunk/test/webapp/WEB-INF/tags/bug55198.tagx (added) +++ tomcat/trunk/test/webapp/WEB-INF/tags/bug55198.tagx Fri Jul 5 16:33:06 2013 @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="ISO-8859-1"?> +<!-- + 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. +--> +<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0"> +<jsp:directive.tag body-content="scriptless" /> +<jsp:text> + <a href="#" onclick="window.alert("${'foo'}")">foo</a> + <a href="#" onclick="window.alert("bar")">bar</a> +</jsp:text> +<jsp:doBody /> +</jsp:root> Added: tomcat/trunk/test/webapp/bug5nnnn/bug55198.jsp URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/bug5nnnn/bug55198.jsp?rev=1500062&view=auto ============================================================================== --- tomcat/trunk/test/webapp/bug5nnnn/bug55198.jsp (added) +++ tomcat/trunk/test/webapp/bug5nnnn/bug55198.jsp Fri Jul 5 16:33:06 2013 @@ -0,0 +1,24 @@ +<%-- + 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. +--%> +<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %> +<html> + <head><title>Bug 55198 test case</title></head> + <body> + <p><tags:bug55198 /></p> + </body> +</html> + Propchange: tomcat/trunk/test/webapp/bug5nnnn/bug55198.jsp ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org