Skip to content

Commit

Permalink
Added test for #11298
Browse files Browse the repository at this point in the history
  • Loading branch information
gregw committed Sep 25, 2024
1 parent 18b9782 commit 018647d
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import jakarta.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.ComplianceViolation;
import org.eclipse.jetty.http.HttpCompliance;
import org.eclipse.jetty.http.UriCompliance;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.LocalConnector;
Expand Down Expand Up @@ -87,8 +88,8 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
{
resp.setContentType("text/plain");
PrintWriter out = resp.getWriter();
List<String> headerNames = new ArrayList<>();
headerNames.addAll(Collections.list(req.getHeaderNames()));
out.printf("%s %s%s%s\n", req.getMethod(), req.getContextPath(), req.getServletPath(), req.getPathInfo());
List<String> headerNames = new ArrayList<>(Collections.list(req.getHeaderNames()));
Collections.sort(headerNames);
for (String name : headerNames)
{
Expand Down Expand Up @@ -183,4 +184,25 @@ public void testFoldedHeader() throws Exception
assertThat("Response headers", response, containsString("X-Http-Violation-0: Line Folding not supported"));
assertThat("Response body", response, containsString("[Name] = [Some Value]"));
}

@Test
public void testAmbiguousSlash() throws Exception
{
String request = """
GET /dump/foo//bar HTTP/1.1\r
Host: local\r
Connection: close\r
\r
""";

String response = connector.getResponse(request);
assertThat(response, containsString("HTTP/1.1 400 Bad"));

connector.getConnectionFactory(HttpConnectionFactory.class).getHttpConfiguration().setUriCompliance(UriCompliance.RFC3986.with("test", UriCompliance.Violation.AMBIGUOUS_EMPTY_SEGMENT));
server.getContainedBeans(ServletHandler.class).stream().findFirst().get().setDecodeAmbiguousURIs(true);

response = connector.getResponse(request);
assertThat(response, containsString("HTTP/1.1 200 OK"));
assertThat(response, containsString("GET /dump/foo//bar"));
}
}

0 comments on commit 018647d

Please sign in to comment.