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 2010/11/12 17:52:02 UTC
svn commit: r1034468 - in /tomcat/trunk: java/org/apache/jasper/compiler/
java/org/apache/jasper/util/ test/org/apache/jasper/compiler/
test/webapp-3.0/bug49nnn/ webapps/docs/
Author: markt
Date: Fri Nov 12 16:52:02 2010
New Revision: 1034468
URL: http://svn.apache.org/viewvc?rev=1034468&view=rev
Log:
Additional tests and fixes for https://issues.apache.org/bugzilla/show_bug.cgi?id=49297
Duplicate attribute rules for the page directive are slightly different.
Based on a patch by genspring
Added:
tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultipleImport1.jsp (with props)
tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultipleImport2.jsp (with props)
tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding1.jsp (with props)
tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding2.jsp (with props)
tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding3.jsp (with props)
tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding4.jsp (with props)
Modified:
tomcat/trunk/java/org/apache/jasper/compiler/Parser.java
tomcat/trunk/java/org/apache/jasper/util/UniqueAttributesImpl.java
tomcat/trunk/test/org/apache/jasper/compiler/TestParser.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/java/org/apache/jasper/compiler/Parser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/compiler/Parser.java?rev=1034468&r1=1034467&r2=1034468&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/compiler/Parser.java (original)
+++ tomcat/trunk/java/org/apache/jasper/compiler/Parser.java Fri Nov 12 16:52:02 2010
@@ -150,7 +150,10 @@ class Parser implements TagConstants {
* Attributes ::= (S Attribute)* S?
*/
Attributes parseAttributes() throws JasperException {
- UniqueAttributesImpl attrs = new UniqueAttributesImpl();
+ return parseAttributes(false);
+ }
+ Attributes parseAttributes(boolean pageDirective) throws JasperException {
+ UniqueAttributesImpl attrs = new UniqueAttributesImpl(pageDirective);
reader.skipSpaces();
int ws = 1;
@@ -177,7 +180,7 @@ class Parser implements TagConstants {
public static Attributes parseAttributes(ParserController pc,
JspReader reader) throws JasperException {
Parser tmpParser = new Parser(pc, reader, false, false, null);
- return tmpParser.parseAttributes();
+ return tmpParser.parseAttributes(true);
}
/**
@@ -327,7 +330,7 @@ class Parser implements TagConstants {
* Attribute)*
*/
private void parsePageDirective(Node parent) throws JasperException {
- Attributes attrs = parseAttributes();
+ Attributes attrs = parseAttributes(true);
Node.PageDirective n = new Node.PageDirective(attrs, start, parent);
/*
Modified: tomcat/trunk/java/org/apache/jasper/util/UniqueAttributesImpl.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/jasper/util/UniqueAttributesImpl.java?rev=1034468&r1=1034467&r2=1034468&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/jasper/util/UniqueAttributesImpl.java (original)
+++ tomcat/trunk/java/org/apache/jasper/util/UniqueAttributesImpl.java Fri Nov 12 16:52:02 2010
@@ -29,7 +29,19 @@ import org.xml.sax.helpers.AttributesImp
*/
public class UniqueAttributesImpl extends AttributesImpl {
- private Set<String> qNames = new HashSet<String>();
+ private static final String IMPORT = "import";
+ private static final String PAGE_ENCODING = "pageEncoding";
+
+ private final boolean pageDirective;
+ private final Set<String> qNames = new HashSet<String>();
+
+ public UniqueAttributesImpl() {
+ this.pageDirective = false;
+ }
+
+ public UniqueAttributesImpl(boolean pageDirective) {
+ this.pageDirective = pageDirective;
+ }
@Override
public void clear() {
@@ -41,7 +53,7 @@ public class UniqueAttributesImpl extend
public void setAttributes(Attributes atts) {
for (int i = 0; i < atts.getLength(); i++) {
if (!qNames.add(atts.getQName(i))) {
- handleDuplicate(atts.getQName(i));
+ handleDuplicate(atts.getQName(i), atts.getValue(i));
}
}
super.setAttributes(atts);
@@ -53,7 +65,7 @@ public class UniqueAttributesImpl extend
if (qNames.add(qName)) {
super.addAttribute(uri, localName, qName, type, value);
} else {
- handleDuplicate(qName);
+ handleDuplicate(qName, value);
}
}
@@ -64,7 +76,7 @@ public class UniqueAttributesImpl extend
if (qNames.add(qName)) {
super.setAttribute(index, uri, localName, qName, type, value);
} else {
- handleDuplicate(qName);
+ handleDuplicate(qName, value);
}
}
@@ -80,8 +92,29 @@ public class UniqueAttributesImpl extend
super.setQName(index, qName);
}
- private void handleDuplicate(String qName) {
+ private void handleDuplicate(String qName, String value) {
+ if (pageDirective) {
+ if (IMPORT.equalsIgnoreCase(qName)) {
+ // Always merge imports
+ int i = super.getIndex(IMPORT);
+ String v = super.getValue(i);
+ super.setValue(i, v + "," + value);
+ return;
+ } else if (PAGE_ENCODING.equalsIgnoreCase(qName)) {
+ // Page encoding can only occur once per file so a second
+ // attribute - even one with a duplicate value - is an error
+ } else {
+ // Other attributes can be repeated if and only if the values
+ // are identical
+ String v = super.getValue(qName);
+ if (v.equals(value)) {
+ return;
+ }
+ }
+ }
+
+ // Ordinary tag attributes can't be repeated, even with identical values
throw new IllegalArgumentException(
- Localizer.getMessage("jsp.error.duplicateqname", qName));
+ Localizer.getMessage("jsp.error.duplicateqname", qName));
}
}
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=1034468&r1=1034467&r2=1034468&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/jasper/compiler/TestParser.java (original)
+++ tomcat/trunk/test/org/apache/jasper/compiler/TestParser.java Fri Nov 12 16:52:02 2010
@@ -144,6 +144,116 @@ public class TestParser extends TomcatBa
assertEquals(500, sc);
}
+ public void testBug49297MultipleImport1() throws Exception {
+
+ Tomcat tomcat = getTomcatInstance();
+
+ File appDir = new File("test/webapp-3.0");
+ // app dir is relative to server home
+ tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+
+ tomcat.start();
+
+ ByteChunk res = new ByteChunk();
+ int sc = getUrl("http://localhost:" + getPort() +
+ "/test/bug49nnn/bug49297MultipleImport1.jsp", res,
+ new HashMap<String,List<String>>());
+
+ assertEquals(200, sc);
+ assertEcho(res.toString(), "OK");
+ }
+
+ public void testBug49297MultipleImport2() throws Exception {
+
+ Tomcat tomcat = getTomcatInstance();
+
+ File appDir = new File("test/webapp-3.0");
+ // app dir is relative to server home
+ tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+
+ tomcat.start();
+
+ ByteChunk res = new ByteChunk();
+ int sc = getUrl("http://localhost:" + getPort() +
+ "/test/bug49nnn/bug49297MultipleImport2.jsp", res,
+ new HashMap<String,List<String>>());
+
+ assertEquals(200, sc);
+ assertEcho(res.toString(), "OK");
+ }
+
+ public void testBug49297MultiplePageEncoding1() throws Exception {
+
+ Tomcat tomcat = getTomcatInstance();
+
+ File appDir = new File("test/webapp-3.0");
+ // app dir is relative to server home
+ tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+
+ tomcat.start();
+
+ ByteChunk res = new ByteChunk();
+ int sc = getUrl("http://localhost:" + getPort() +
+ "/test/bug49nnn/bug49297MultiplePageEncoding1.jsp", res,
+ new HashMap<String,List<String>>());
+
+ assertEquals(500, sc);
+ }
+
+ public void testBug49297MultiplePageEncoding2() throws Exception {
+
+ Tomcat tomcat = getTomcatInstance();
+
+ File appDir = new File("test/webapp-3.0");
+ // app dir is relative to server home
+ tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+
+ tomcat.start();
+
+ ByteChunk res = new ByteChunk();
+ int sc = getUrl("http://localhost:" + getPort() +
+ "/test/bug49nnn/bug49297MultiplePageEncoding2.jsp", res,
+ new HashMap<String,List<String>>());
+
+ assertEquals(500, sc);
+ }
+
+ public void testBug49297MultiplePageEncoding3() throws Exception {
+
+ Tomcat tomcat = getTomcatInstance();
+
+ File appDir = new File("test/webapp-3.0");
+ // app dir is relative to server home
+ tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+
+ tomcat.start();
+
+ ByteChunk res = new ByteChunk();
+ int sc = getUrl("http://localhost:" + getPort() +
+ "/test/bug49nnn/bug49297MultiplePageEncoding3.jsp", res,
+ new HashMap<String,List<String>>());
+
+ assertEquals(500, sc);
+ }
+
+ public void testBug49297MultiplePageEncoding4() throws Exception {
+
+ Tomcat tomcat = getTomcatInstance();
+
+ File appDir = new File("test/webapp-3.0");
+ // app dir is relative to server home
+ tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+
+ tomcat.start();
+
+ ByteChunk res = new ByteChunk();
+ int sc = getUrl("http://localhost:" + getPort() +
+ "/test/bug49nnn/bug49297MultiplePageEncoding4.jsp", res,
+ new HashMap<String,List<String>>());
+
+ assertEquals(500, sc);
+ }
+
/** 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-3.0/bug49nnn/bug49297MultipleImport1.jsp
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultipleImport1.jsp?rev=1034468&view=auto
==============================================================================
--- tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultipleImport1.jsp (added)
+++ tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultipleImport1.jsp Fri Nov 12 16:52:02 2010
@@ -0,0 +1,28 @@
+<%--
+ 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.
+--%>
+<%@page import="java.util.List" import="java.util.ArrayList" %>
+<html>
+ <head><title>Bug 49297 multiple import test case</title></head>
+ <body>
+ <%
+ // Make sure the imports above do work
+ List<String> l = new ArrayList<String>();
+ l.add("OK");
+ %>
+ <p><%=l.get(0)%></p>
+ </body>
+</html>
\ No newline at end of file
Propchange: tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultipleImport1.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultipleImport2.jsp
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultipleImport2.jsp?rev=1034468&view=auto
==============================================================================
--- tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultipleImport2.jsp (added)
+++ tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultipleImport2.jsp Fri Nov 12 16:52:02 2010
@@ -0,0 +1,29 @@
+<%--
+ 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.
+--%>
+<%@page import="java.util.List" %>
+<%@page import="java.util.ArrayList" %>
+<html>
+ <head><title>Bug 49297 multiple import test case</title></head>
+ <body>
+ <%
+ // Make sure the imports above do work
+ List<String> l = new ArrayList<String>();
+ l.add("OK");
+ %>
+ <p><%=l.get(0)%></p>
+ </body>
+</html>
\ No newline at end of file
Propchange: tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultipleImport2.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding1.jsp
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding1.jsp?rev=1034468&view=auto
==============================================================================
--- tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding1.jsp (added)
+++ tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding1.jsp Fri Nov 12 16:52:02 2010
@@ -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.
+--%>
+<%@page pageEncoding="ISO-8859-1" %>
+<%@page pageEncoding="ISO-8859-1" %>
+<html>
+ <head><title>Bug 49297 multiple pageEncoding test case</title></head>
+ <body>
+ <p>Should fail</p>
+ </body>
+</html>
\ No newline at end of file
Propchange: tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding1.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding2.jsp
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding2.jsp?rev=1034468&view=auto
==============================================================================
--- tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding2.jsp (added)
+++ tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding2.jsp Fri Nov 12 16:52:02 2010
@@ -0,0 +1,23 @@
+<%--
+ 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.
+--%>
+<%@page pageEncoding="ISO-8859-1" pageEncoding="ISO-8859-1" %>
+<html>
+ <head><title>Bug 49297 multiple pageEncoding test case</title></head>
+ <body>
+ <p>Should fail</p>
+ </body>
+</html>
\ No newline at end of file
Propchange: tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding2.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding3.jsp
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding3.jsp?rev=1034468&view=auto
==============================================================================
--- tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding3.jsp (added)
+++ tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding3.jsp Fri Nov 12 16:52:02 2010
@@ -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.
+--%>
+<%@page pageEncoding="ISO-8859-1" %>
+<%@page pageEncoding="UTF-8" %>
+<html>
+ <head><title>Bug 49297 multiple pageEncoding test case</title></head>
+ <body>
+ <p>Should fail</p>
+ </body>
+</html>
\ No newline at end of file
Propchange: tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding3.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Added: tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding4.jsp
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding4.jsp?rev=1034468&view=auto
==============================================================================
--- tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding4.jsp (added)
+++ tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding4.jsp Fri Nov 12 16:52:02 2010
@@ -0,0 +1,23 @@
+<%--
+ 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.
+--%>
+<%@page pageEncoding="ISO-8859-1" pageEncoding="UTF-8"%>
+<html>
+ <head><title>Bug 49297 multiple pageEncoding test case</title></head>
+ <body>
+ <p>Should fail</p>
+ </body>
+</html>
\ No newline at end of file
Propchange: tomcat/trunk/test/webapp-3.0/bug49nnn/bug49297MultiplePageEncoding4.jsp
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1034468&r1=1034467&r2=1034468&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Fri Nov 12 16:52:02 2010
@@ -155,7 +155,9 @@
whitespace before the attribute name. The whitespace test can be
disabled by setting the system property
<code>org.apache.jasper.compiler.Parser.STRICT_WHITESPACE</code> to
- <code>false</code>. (markt)
+ <code>false</code>. Attributes of the page directive have slightly
+ different rules. The implementation of that part of the fix is based on
+ a patch by genspring. (markt)
</fix>
<fix>
<bug>50105</bug>: When processing composite EL expressions use
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org