Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2015-06-29 20:33:41 -0400
committerJoakim Erdfelt2015-06-29 20:35:18 -0400
commitf644926b2b2edbdf1c16bd1a13549e705d6f2ca9 (patch)
tree84043a00066160fa8b6379e47f339ef9456f68f0 /apache-jstl
parentbc71a57afa8a8318cabb707ceefbbf24b98bf609 (diff)
downloadorg.eclipse.jetty.project-f644926b2b2edbdf1c16bd1a13549e705d6f2ca9.tar.gz
org.eclipse.jetty.project-f644926b2b2edbdf1c16bd1a13549e705d6f2ca9.tar.xz
org.eclipse.jetty.project-f644926b2b2edbdf1c16bd1a13549e705d6f2ca9.zip
471388 - StringIndexOutOfBoundsException when using <c:url> with parameters
Adding testcase to demonstrate the bug
Diffstat (limited to 'apache-jstl')
-rw-r--r--apache-jstl/pom.xml27
-rw-r--r--apache-jstl/src/test/java/org/eclipse/jetty/jstl/JspConfig.java90
-rw-r--r--apache-jstl/src/test/java/org/eclipse/jetty/jstl/JstlTest.java97
-rw-r--r--apache-jstl/src/test/webapp/WEB-INF/web.xml7
-rw-r--r--apache-jstl/src/test/webapp/ref.jsp2
-rw-r--r--apache-jstl/src/test/webapp/urls.jsp6
6 files changed, 229 insertions, 0 deletions
diff --git a/apache-jstl/pom.xml b/apache-jstl/pom.xml
index d5528a247f..e736270bcc 100644
--- a/apache-jstl/pom.xml
+++ b/apache-jstl/pom.xml
@@ -30,6 +30,33 @@
<groupId>org.apache.taglibs</groupId>
<artifactId>taglibs-standard-impl</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jetty.toolchain</groupId>
+ <artifactId>jetty-test-helper</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>apache-jsp</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-annotations</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-webapp</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
diff --git a/apache-jstl/src/test/java/org/eclipse/jetty/jstl/JspConfig.java b/apache-jstl/src/test/java/org/eclipse/jetty/jstl/JspConfig.java
new file mode 100644
index 0000000000..45126d19d9
--- /dev/null
+++ b/apache-jstl/src/test/java/org/eclipse/jetty/jstl/JspConfig.java
@@ -0,0 +1,90 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.jstl;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tomcat.InstanceManager;
+import org.apache.tomcat.SimpleInstanceManager;
+import org.eclipse.jetty.annotations.ServletContainerInitializersStarter;
+import org.eclipse.jetty.apache.jsp.JettyJasperInitializer;
+import org.eclipse.jetty.jsp.JettyJspServlet;
+import org.eclipse.jetty.plus.annotation.ContainerInitializer;
+import org.eclipse.jetty.servlet.DefaultServlet;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.eclipse.jetty.webapp.WebAppContext;
+
+/**
+ * Attempt at collecting up all of the JSP specific configuration bits and pieces into a single place
+ * for WebAppContext users to utilize.
+ */
+public class JspConfig
+{
+ public static void init(WebAppContext context, URI baseUri, File scratchDir)
+ {
+ context.setAttribute("javax.servlet.context.tempdir", scratchDir);
+ context.setWar(baseUri.toASCIIString());
+ context.setResourceBase(baseUri.toASCIIString());
+
+ // Set JSP to use Standard JavaC always
+ System.setProperty("org.apache.jasper.compiler.disablejsr199", "false");
+
+ // Container Initializers for JSP
+ context.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
+ ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/.*taglibs.*\\.jar$");
+
+ JettyJasperInitializer sci = new JettyJasperInitializer();
+ ContainerInitializer initializer = new ContainerInitializer(sci, null);
+ List<ContainerInitializer> initializers = new ArrayList<ContainerInitializer>();
+ initializers.add(initializer);
+
+ context.setAttribute("org.eclipse.jetty.containerInitializers", initializers);
+ context.addBean(new ServletContainerInitializersStarter(context), true);
+
+ // Apache Jasper JSP specific instance management
+ context.setAttribute(InstanceManager.class.getName(), new SimpleInstanceManager());
+
+ // Class Loader requirements for JSP
+ ClassLoader jspClassLoader = new URLClassLoader(new URL[0], context.getClass().getClassLoader());
+ context.setClassLoader(jspClassLoader);
+
+ // JSP Servlet
+ ServletHolder holderJsp = new ServletHolder("jsp", JettyJspServlet.class);
+ holderJsp.setInitOrder(0);
+ holderJsp.setInitParameter("logVerbosityLevel", "DEBUG");
+ holderJsp.setInitParameter("fork", "false");
+ holderJsp.setInitParameter("xpoweredBy", "false");
+ holderJsp.setInitParameter("compilerTargetVM", "1.8");
+ holderJsp.setInitParameter("compilerSourceVM", "1.8");
+ holderJsp.setInitParameter("keepgenerated", "true");
+ context.addServlet(holderJsp, "*.jsp");
+
+ // Default Servlet
+ ServletHolder holderDefault = new ServletHolder("default", DefaultServlet.class);
+ holderDefault.setInitParameter("resourceBase", baseUri.toASCIIString());
+ holderDefault.setInitParameter("dirAllowed", "true");
+
+ context.addServlet(holderDefault, "/");
+ }
+}
diff --git a/apache-jstl/src/test/java/org/eclipse/jetty/jstl/JstlTest.java b/apache-jstl/src/test/java/org/eclipse/jetty/jstl/JstlTest.java
new file mode 100644
index 0000000000..719965cfd0
--- /dev/null
+++ b/apache-jstl/src/test/java/org/eclipse/jetty/jstl/JstlTest.java
@@ -0,0 +1,97 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd.
+// ------------------------------------------------------------------------
+// All rights reserved. This program and the accompanying materials
+// are made available under the terms of the Eclipse Public License v1.0
+// and Apache License v2.0 which accompanies this distribution.
+//
+// The Eclipse Public License is available at
+// http://www.eclipse.org/legal/epl-v10.html
+//
+// The Apache License v2.0 is available at
+// http://www.opensource.org/licenses/apache2.0.php
+//
+// You may elect to redistribute this code under either of these licenses.
+// ========================================================================
+//
+
+package org.eclipse.jetty.jstl;
+
+import static org.hamcrest.Matchers.*;
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.toolchain.test.FS;
+import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
+import org.eclipse.jetty.toolchain.test.SimpleRequest;
+import org.eclipse.jetty.webapp.WebAppContext;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class JstlTest
+{
+ private static Server server;
+ private static URI baseUri;
+
+ @BeforeClass
+ public static void startServer() throws Exception
+ {
+ // Setup Server
+ server = new Server();
+ ServerConnector connector = new ServerConnector(server);
+ connector.setPort(0);
+ server.addConnector(connector);
+
+ // Setup WebAppContext
+ File testWebAppDir = MavenTestingUtils.getProjectDir("src/test/webapp");
+
+ WebAppContext context = new WebAppContext();
+ context.setContextPath("/");
+
+ File scratchDir = MavenTestingUtils.getTargetFile("tests/" + JstlTest.class.getSimpleName() + "-scratch");
+ FS.ensureEmpty(scratchDir);
+ JspConfig.init(context,testWebAppDir.toURI(),scratchDir);
+
+ server.setHandler(context);
+
+ // Start Server
+ server.start();
+
+ // Figure out Base URI
+ String host = connector.getHost();
+ if (host == null)
+ {
+ host = "localhost";
+ }
+ int port = connector.getLocalPort();
+ baseUri = new URI(String.format("http://%s:%d/",host,port));
+ }
+
+ @AfterClass
+ public static void stopServer() throws Exception
+ {
+ server.stop();
+ }
+
+ @Test
+ @Ignore("Need sanity review from Jan and/or Greg")
+ public void testUrlsBasic() throws IOException
+ {
+ SimpleRequest req = new SimpleRequest(baseUri);
+ String resp = req.getString("/urls.jsp");
+ assertThat("Response should be JSP processed", resp, not(containsString("<c:url")));
+ assertThat("Response", resp, containsString("[c:url value] = /ref.jsp;jsessionid="));
+ assertThat("Response", resp, containsString("[c:url param] = /ref.jsp;key=value;jsessionid="));
+
+ System.err.println("Response:");
+ System.err.println(resp);
+ }
+}
diff --git a/apache-jstl/src/test/webapp/WEB-INF/web.xml b/apache-jstl/src/test/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000000..b05e490c65
--- /dev/null
+++ b/apache-jstl/src/test/webapp/WEB-INF/web.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
+ version="3.1">
+ <description>Test webapp for JSTL</description>
+</web-app> \ No newline at end of file
diff --git a/apache-jstl/src/test/webapp/ref.jsp b/apache-jstl/src/test/webapp/ref.jsp
new file mode 100644
index 0000000000..0debf75489
--- /dev/null
+++ b/apache-jstl/src/test/webapp/ref.jsp
@@ -0,0 +1,2 @@
+<%@ page contentType="text/plain; charset=UTF-8" %>
+Reference Page: No useful content here, just used for other tests \ No newline at end of file
diff --git a/apache-jstl/src/test/webapp/urls.jsp b/apache-jstl/src/test/webapp/urls.jsp
new file mode 100644
index 0000000000..bc18e9ac5f
--- /dev/null
+++ b/apache-jstl/src/test/webapp/urls.jsp
@@ -0,0 +1,6 @@
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+<%@ page contentType="text/plain; charset=UTF-8" %>
+Title: JSTL c:url Tests
+[c:url value] = <c:url value="/ref.jsp" />
+<c:set var="foo" value="ref.jsp;key=value"/>
+[c:url param] = <c:url value="${foo}"><c:param name="noframe" value="true"/></c:url>

Back to the top