JETTY-1277 Fixed sendRedirect encoding of relative locations
This commit is contained in:
parent
26c8cc8514
commit
f8b8a2e770
|
@ -430,7 +430,7 @@ public class Response implements HttpServletResponse
|
|||
if (!canonical.equals(path))
|
||||
{
|
||||
buf = _connection.getRequest().getRootURL();
|
||||
buf.append(canonical);
|
||||
buf.append(URIUtil.encodePath(canonical));
|
||||
if (uri.getQuery()!=null)
|
||||
{
|
||||
buf.append('?');
|
||||
|
|
|
@ -381,31 +381,45 @@ public class ResponseTest
|
|||
public void testSendRedirect()
|
||||
throws Exception
|
||||
{
|
||||
ByteArrayEndPoint out=new ByteArrayEndPoint(new byte[]{},4096);
|
||||
HttpConnection connection=new TestHttpConnection(connector,out, connector.getServer());
|
||||
Response response = new Response(connection);
|
||||
Request request = connection.getRequest();
|
||||
request.setServerName("myhost");
|
||||
request.setServerPort(8888);
|
||||
request.setUri(new HttpURI("/path/info;param;jsessionid=12345?query=0&more=1#target"));
|
||||
request.setContextPath("/path");
|
||||
request.setRequestedSessionId("12345");
|
||||
request.setRequestedSessionIdFromCookie(false);
|
||||
AbstractSessionManager manager=new HashSessionManager();
|
||||
manager.setSessionIdManager(new HashSessionIdManager());
|
||||
request.setSessionManager(manager);
|
||||
request.setSession(new TestSession(manager,"12345"));
|
||||
manager.setCheckingRemoteSessionIdEncoding(false);
|
||||
String[][] tests={
|
||||
{"/other/location?name=value","http://myhost:8888/other/location;jsessionid=12345?name=value"},
|
||||
{"/other/location","http://myhost:8888/other/location"},
|
||||
{"/other/l%20cation","http://myhost:8888/other/l%20cation"},
|
||||
{"location","http://myhost:8888/path/location"},
|
||||
{"./location","http://myhost:8888/path/location"},
|
||||
{"../location","http://myhost:8888/location"},
|
||||
{"/other/l%20cation","http://myhost:8888/other/l%20cation"},
|
||||
{"l%20cation","http://myhost:8888/path/l%20cation"},
|
||||
{"./l%20cation","http://myhost:8888/path/l%20cation"},
|
||||
{"../l%20cation","http://myhost:8888/l%20cation"},
|
||||
};
|
||||
|
||||
for (int i=1;i<tests.length;i++)
|
||||
{
|
||||
ByteArrayEndPoint out=new ByteArrayEndPoint(new byte[]{},4096);
|
||||
HttpConnection connection=new TestHttpConnection(connector,out, connector.getServer());
|
||||
Response response = new Response(connection);
|
||||
Request request = connection.getRequest();
|
||||
request.setServerName("myhost");
|
||||
request.setServerPort(8888);
|
||||
request.setUri(new HttpURI("/path/info;param;jsessionid=12345?query=0&more=1#target"));
|
||||
request.setContextPath("/path");
|
||||
request.setRequestedSessionId("12345");
|
||||
request.setRequestedSessionIdFromCookie(i>0);
|
||||
AbstractSessionManager manager=new HashSessionManager();
|
||||
manager.setSessionIdManager(new HashSessionIdManager());
|
||||
request.setSessionManager(manager);
|
||||
request.setSession(new TestSession(manager,"12345"));
|
||||
manager.setCheckingRemoteSessionIdEncoding(false);
|
||||
|
||||
response.sendRedirect("/other/location");
|
||||
|
||||
String location = out.getOut().toString();
|
||||
int l=location.indexOf("Location: ");
|
||||
int e=location.indexOf('\n',l);
|
||||
location=location.substring(l+10,e).trim();
|
||||
|
||||
assertEquals("http://myhost:8888/other/location;jsessionid=12345",location);
|
||||
|
||||
response.sendRedirect(tests[i][0]);
|
||||
|
||||
String location = out.getOut().toString();
|
||||
int l=location.indexOf("Location: ");
|
||||
int e=location.indexOf('\n',l);
|
||||
location=location.substring(l+10,e).trim();
|
||||
assertEquals(tests[i][0],tests[i][1],location);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue