You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2015/01/21 08:47:02 UTC

[2/2] struts git commit: WW-4448 Strips params and replaces spaces

WW-4448 Strips params and replaces spaces


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/0f44e11c
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/0f44e11c
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/0f44e11c

Branch: refs/heads/develop
Commit: 0f44e11cd1f3cff51ed4a2a10dec593d8822ade2
Parents: e3428c5
Author: Lukasz Lenart <lu...@apache.org>
Authored: Wed Jan 21 08:46:49 2015 +0100
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Wed Jan 21 08:46:49 2015 +0100

----------------------------------------------------------------------
 .../dispatcher/ServletRedirectResult.java       |  6 +++-
 .../dispatcher/ServletRedirectResultTest.java   | 30 ++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/0f44e11c/core/src/main/java/org/apache/struts2/dispatcher/ServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ServletRedirectResult.java b/core/src/main/java/org/apache/struts2/dispatcher/ServletRedirectResult.java
index b6cd282..60f5584 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/ServletRedirectResult.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/ServletRedirectResult.java
@@ -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()) {

http://git-wip-us.apache.org/repos/asf/struts/blob/0f44e11c/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java b/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java
index 56cfe9d..ab40dfc 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java
@@ -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);