struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [06/22] git commit: Uses URL class to check if location is path or full url
Date Fri, 21 Mar 2014 20:15:45 GMT
Uses URL class to check if location is path or full url


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

Branch: refs/heads/feature/use-js-to-support-multiple-buttons
Commit: 4b7d2e35d09225a7c8b3b410588131b692b2730f
Parents: bcd61a0
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Sun Mar 9 21:46:33 2014 +0100
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Sun Mar 9 21:46:33 2014 +0100

----------------------------------------------------------------------
 .../dispatcher/ServletRedirectResult.java       | 23 ++++++++++++++------
 1 file changed, 16 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/4b7d2e35/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 abc69eb..038d8c3 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/ServletRedirectResult.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/ServletRedirectResult.java
@@ -37,6 +37,9 @@ import org.apache.struts2.views.util.UrlHelper;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URI;
+import java.net.URLConnection;
 import java.util.*;
 
 import static javax.servlet.http.HttpServletResponse.SC_FOUND;
@@ -262,13 +265,19 @@ public class ServletRedirectResult extends StrutsResultSupport implements
Reflec
 
     }
 
-    private boolean isPathUrl(String url) {
-        // filter out "http:", "https:", "mailto:", "file:", "ftp:"
-        return !url.startsWith("http:")
-                && !url.startsWith("https:")
-                && !url.startsWith("mailto:")
-                && !url.startsWith("file:")
-                && !url.startsWith("ftp:");
+    /**
+     * Checks if url is simple path or either full url
+     *
+     * @param url string
+     * @return true if it's just a path not a full url
+     */
+    protected boolean isPathUrl(String url) {
+        try {
+            return URI.create(url).getScheme() == null;
+        } catch (IllegalArgumentException e) {
+            LOG.debug("[#0] isn't a valid URL", e, url);
+            return false;
+        }
     }
 
     /**


Mime
View raw message