You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2013/06/28 18:00:51 UTC

[31/50] [abbrv] android commit: CB-3854: Added support for wildcard. This probably could be improved, but it does work

CB-3854: Added support for wildcard.  This probably could be improved, but it does work


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

Branch: refs/heads/2.9.x
Commit: f1b377bf070099c3e437fd9a2e2d516d6bfea42b
Parents: 3ace934
Author: Joe Bowser <bo...@apache.org>
Authored: Thu Jun 20 16:32:18 2013 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Thu Jun 20 16:32:18 2013 -0700

----------------------------------------------------------------------
 framework/src/org/apache/cordova/Config.java | 25 ++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/f1b377bf/framework/src/org/apache/cordova/Config.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/Config.java b/framework/src/org/apache/cordova/Config.java
index c2ced34..a10ed81 100644
--- a/framework/src/org/apache/cordova/Config.java
+++ b/framework/src/org/apache/cordova/Config.java
@@ -203,6 +203,20 @@ public class Config {
         self._addWhiteListEntry(origin, subdomains);
     }
 
+    /*
+     * Trying to figure out how to match * is a pain
+     * So, we don't use a regex here
+     */
+    
+    private boolean originHasWildcard(String origin){
+        //First, check for a protocol, then split it if it has one.
+        if(origin.contains("//"))
+        {
+            origin = origin.split("//")[1];
+        }
+        origin.matches("\\*\\.[a-z]+\\.[a-z]+");
+        return origin.startsWith("*");
+    }
 
     private void _addWhiteListEntry(String origin, boolean subdomains) {
         try {
@@ -210,8 +224,16 @@ public class Config {
             if (origin.compareTo("*") == 0) {
                 LOG.d(TAG, "Unlimited access to network resources");
                 this.whiteList.add(Pattern.compile(".*"));
-            } else { // specific access
+            }
+            else { // specific access
                 // check if subdomains should be included
+                if(originHasWildcard(origin))
+                {
+                    subdomains = true;
+                    //Remove the wildcard so this works properly
+                    origin = origin.replace("*.", "");
+                }
+                
                 // TODO: we should not add more domains if * has already been added
                 Pattern schemeRegex = Pattern.compile("^[a-z-]+://");
                 Matcher matcher = schemeRegex.matcher(origin);
@@ -250,6 +272,7 @@ public class Config {
         }
     }
 
+
     /**
      * Determine if URL is in approved list of URLs to load.
      *