-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+ Fix RegexPathSpec pathInfo + Test regression option to 93 behaviour Signed-off-by: Greg Wilkins <[email protected]>
- Loading branch information
Showing
4 changed files
with
137 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
jetty-servlet/src/test/java/org/eclipse/jetty/servlet/RegressionServletTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2022 Mort Bay Consulting Pty Ltd and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 | ||
// which is available at https://www.apache.org/licenses/LICENSE-2.0. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.servlet; | ||
|
||
import org.eclipse.jetty.http.pathmap.AbstractPathSpec; | ||
import org.eclipse.jetty.http.pathmap.PathSpec; | ||
import org.eclipse.jetty.http.pathmap.PathSpecGroup; | ||
import org.eclipse.jetty.server.LocalConnector; | ||
import org.eclipse.jetty.server.Server; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
|
||
public class RegressionServletTest | ||
{ | ||
private Server _server; | ||
private LocalConnector _connector; | ||
private ServletContextHandler _servletContextHandler; | ||
|
||
@BeforeEach | ||
public void beforeEach() | ||
{ | ||
_server = new Server(); | ||
_connector = new LocalConnector(_server); | ||
|
||
_servletContextHandler = new ServletContextHandler(_server, "/ctx"); | ||
_servletContextHandler.setServletHandler(new ServletHandler() | ||
{ | ||
@Override | ||
protected PathSpec asPathSpec(String pathSpec) | ||
{ | ||
if (pathSpec.startsWith("/") && pathSpec.contains("*")) | ||
return new AbstractPathSpec() | ||
{ | ||
@Override | ||
public int getSpecLength() | ||
{ | ||
return pathSpec.length(); | ||
} | ||
|
||
@Override | ||
public PathSpecGroup getGroup() | ||
{ | ||
return PathSpecGroup.EXACT; | ||
} | ||
|
||
@Override | ||
public int getPathDepth() | ||
{ | ||
return 0; | ||
} | ||
|
||
@Override | ||
public String getPathInfo(String path) | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getPathMatch(String path) | ||
{ | ||
return path; | ||
} | ||
|
||
@Override | ||
public String getDeclaration() | ||
{ | ||
return pathSpec; | ||
} | ||
|
||
@Override | ||
public String getPrefix() | ||
{ | ||
return pathSpec; | ||
} | ||
|
||
@Override | ||
public String getSuffix() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean matches(String path) | ||
{ | ||
return pathSpec.equals(path); | ||
} | ||
}; | ||
return super.asPathSpec(pathSpec); | ||
} | ||
}); | ||
|
||
_server.setHandler(_servletContextHandler); | ||
_server.addConnector(_connector); | ||
} | ||
|
||
@Test | ||
public void testHello() throws Exception | ||
{ | ||
_servletContextHandler.addServlet(new ServletHolder(new ServletContextHandlerTest.HelloServlet()), "/*.xhtml"); | ||
_server.start(); | ||
|
||
assertThat(_connector.getResponse("GET /ctx/hello HTTP/1.0\r\n\r\n"), containsString(" 404")); | ||
assertThat(_connector.getResponse("GET /ctx/hello.xhtml HTTP/1.0\r\n\r\n"), containsString(" 404")); | ||
assertThat(_connector.getResponse("GET /ctx/*.xhtml HTTP/1.0\r\n\r\n"), containsString("Hello World")); | ||
} | ||
} |