471388 - StringIndexOutOfBoundsException when using <c:url> with parameters
Adding testcase to demonstrate the bug
This commit is contained in:
parent
bc71a57afa
commit
f644926b2b
|
@ -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>
|
||||
|
|
|
@ -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, "/");
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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>
|
|
@ -0,0 +1,2 @@
|
|||
<%@ page contentType="text/plain; charset=UTF-8" %>
|
||||
Reference Page: No useful content here, just used for other tests
|
|
@ -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>
|
Loading…
Reference in New Issue