From: markt Date: Mon, 23 Aug 2010 19:23:28 +0000 (+0000) Subject: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49726 X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=9af3129893bd4fea64c753abe8707181d53e3cff;p=tomcat7.0 Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49726 Specifying a default content type via a JSP property group should not prevent a page from setting some other content type Includes test cases git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@988262 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/jasper/compiler/Compiler.java b/java/org/apache/jasper/compiler/Compiler.java index 0c02fbda5..7b9e03c4f 100644 --- a/java/org/apache/jasper/compiler/Compiler.java +++ b/java/org/apache/jasper/compiler/Compiler.java @@ -140,9 +140,8 @@ public abstract class Compiler { pageInfo.setTrimDirectiveWhitespaces(JspUtil.booleanValue(jspProperty .isTrimDirectiveWhitespaces())); } - if (jspProperty.getDefaultContentType() != null) { - pageInfo.setContentType(jspProperty.getDefaultContentType()); - } + // Default ContentType processing is deferred until after the page has + // been parsed if (jspProperty.getBuffer() != null) { pageInfo.setBufferValue(jspProperty.getBuffer(), null, errDispatcher); @@ -197,6 +196,12 @@ public abstract class Compiler { // Pass 2 - the whole translation unit pageNodes = parserCtl.parse(ctxt.getJspFile()); + // Leave this until now since it can only be set once - bug 49726 + if (pageInfo.getContentType() == null && + jspProperty.getDefaultContentType() != null) { + pageInfo.setContentType(jspProperty.getDefaultContentType()); + } + if (ctxt.isPrototypeMode()) { // generate prototype .java file for the tag file writer = setupContextWriter(javaFileName); diff --git a/test/org/apache/jasper/compiler/TestCompiler.java b/test/org/apache/jasper/compiler/TestCompiler.java new file mode 100644 index 000000000..e9d01f64b --- /dev/null +++ b/test/org/apache/jasper/compiler/TestCompiler.java @@ -0,0 +1,77 @@ +/* + * 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 java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.catalina.startup.Tomcat; +import org.apache.catalina.startup.TomcatBaseTest; +import org.apache.tomcat.util.buf.ByteChunk; + +public class TestCompiler extends TomcatBaseTest { + + public void testBug49726a() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File appDir = new File("test/webapp-3.0"); + tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); + tomcat.start(); + + ByteChunk res = new ByteChunk(); + Map> headers = new HashMap>(); + + getUrl("http://localhost:" + getPort() + "/test/bug49726a.jsp", res, + headers); + + // Check request completed + String result = res.toString(); + assertEcho(result, "OK"); + + // Check content type + assertTrue(headers.get("Content-Type").get(0).startsWith("text/html")); + } + + public void testBug49726b() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + File appDir = new File("test/webapp-3.0"); + tomcat.addWebapp(null, "/test", appDir.getAbsolutePath()); + tomcat.start(); + + ByteChunk res = new ByteChunk(); + Map> headers = new HashMap>(); + + getUrl("http://localhost:" + getPort() + "/test/bug49726b.jsp", res, + headers); + + // Check request completed + String result = res.toString(); + assertEcho(result, "OK"); + + // Check content type + assertTrue(headers.get("Content-Type").get(0).startsWith("text/plain")); + } + + /** Assertion for text printed by tags:echo */ + private static void assertEcho(String result, String expected) { + assertTrue(result.indexOf("

" + expected + "

") > 0); + } +} diff --git a/test/webapp-3.0/WEB-INF/web.xml b/test/webapp-3.0/WEB-INF/web.xml index 947d4ea32..ac2852fb1 100644 --- a/test/webapp-3.0/WEB-INF/web.xml +++ b/test/webapp-3.0/WEB-INF/web.xml @@ -27,4 +27,11 @@ Used as part of the Tomcat unit tests when a full web application is required. + + + text/plain + /bug49726a.jsp + /bug49726b.jsp + + \ No newline at end of file diff --git a/test/webapp-3.0/bug49726a.jsp b/test/webapp-3.0/bug49726a.jsp new file mode 100644 index 000000000..a9e177b4a --- /dev/null +++ b/test/webapp-3.0/bug49726a.jsp @@ -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 contentType="text/html"%> + + Bug 49726 test case + +

OK

+ + + diff --git a/test/webapp-3.0/bug49726b.jsp b/test/webapp-3.0/bug49726b.jsp new file mode 100644 index 000000000..eaf7737fe --- /dev/null +++ b/test/webapp-3.0/bug49726b.jsp @@ -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. +--%> + + Bug 49726 test case + +

OK

+ + + diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 0cd5ebf14..fd73b0b5e 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -76,6 +76,15 @@ + + + + 49726: Specifying a default content type via a JSP property + group should not prevent a page from setting some other content type. + (markt) + + +