WW-4448 Strips params and replaces spaces

This commit is contained in:
Lukasz Lenart
2015-01-21 08:46:49 +01:00
parent e3428c5fe5
commit 0f44e11cd1
2 changed files with 35 additions and 1 deletions
@@ -272,7 +272,11 @@ public class ServletRedirectResult extends StrutsResultSupport implements Reflec
*/
protected boolean isPathUrl(String url) {
try {
URI uri = URI.create(url);
String rawUrl = url;
if (url.contains("?")) {
rawUrl = url.substring(0, url.indexOf("?"));
}
URI uri = URI.create(rawUrl);
if (uri.isAbsolute()) {
URL validUrl = uri.toURL();
if (LOG.isDebugEnabled()) {
@@ -100,6 +100,36 @@ public class ServletRedirectResultTest extends StrutsInternalTestCase implements
}
}
public void testFullUrlRedirectWithSpaces() {
view.setLocation("http://localhost/bar/foo some.pdf");
responseMock.expectAndReturn("encodeRedirectURL", C.args(C.eq("http://localhost/bar/foo some.pdf")), "http://localhost/bar/foo some.pdf");
responseMock.expect("sendRedirect", C.args(C.eq("http://localhost/bar/foo some.pdf")));
try {
view.execute(ai);
requestMock.verify();
responseMock.verify();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
public void testFullUrlRedirectWithParams() {
view.setLocation("http://localhost/bar/foo.action?param=1&param 2=3");
responseMock.expectAndReturn("encodeRedirectURL", C.args(C.eq("http://localhost/bar/foo.action?param=1&param 2=3")), "http://localhost/bar/foo.action?param=1&param 2=3");
responseMock.expect("sendRedirect", C.args(C.eq("http://localhost/bar/foo.action?param=1&param 2=3")));
try {
view.execute(ai);
requestMock.verify();
responseMock.verify();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
public void testAbsoluteRedirect303() {
view.setLocation("/bar/foo.jsp");
view.setStatusCode(303);