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:01 UTC

[1/2] struts git commit: Extracts string into constant

Repository: struts
Updated Branches:
  refs/heads/develop 243378937 -> 0f44e11cd


Extracts string into constant


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

Branch: refs/heads/develop
Commit: e3428c5fe54b9e2b95f5ac1db0e8814118ac7b3c
Parents: 2433789
Author: Lukasz Lenart <lu...@apache.org>
Authored: Wed Jan 21 08:15:41 2015 +0100
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Wed Jan 21 08:15:41 2015 +0100

----------------------------------------------------------------------
 .../org/apache/struts2/dispatcher/StrutsResultSupport.java    | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/e3428c5f/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java b/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java
index 269ed87..bbcffa3 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/StrutsResultSupport.java
@@ -110,6 +110,9 @@ public abstract class StrutsResultSupport implements Result, StrutsStatics {
     /** The default parameter */
     public static final String DEFAULT_PARAM = "location";
 
+    /** use UTF-8 as this is the recommended encoding by W3C to avoid incompatibilities. */
+    public static final String DEFAULT_URL_ENCODING = "UTF-8";
+
     private boolean parse;
     private boolean encode;
     private String location;
@@ -240,9 +243,7 @@ public abstract class StrutsResultSupport implements Result, StrutsStatics {
             if (encode) {
                 if (parsedValue != null) {
                     try {
-                        // use UTF-8 as this is the recommended encoding by W3C to
-                        // avoid incompatibilities.
-                        return URLEncoder.encode(parsedValue, "UTF-8");
+                        return URLEncoder.encode(parsedValue, DEFAULT_URL_ENCODING);
                     }
                     catch(UnsupportedEncodingException e) {
                         if (LOG.isWarnEnabled()) {


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

Posted by lu...@apache.org.
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);