brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [4/7] brooklyn-server git commit: fix url schema and test
Date Wed, 17 Feb 2016 00:31:41 GMT
fix url schema and test


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/3db19cfd
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/3db19cfd
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/3db19cfd

Branch: refs/heads/master
Commit: 3db19cfdbf2c60ac17f1291ee6239934f55be522
Parents: 581ad0d
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Feb 9 15:39:35 2016 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Tue Feb 16 17:53:03 2016 +0000

----------------------------------------------------------------------
 .../src/main/java/org/apache/brooklyn/util/net/Urls.java    | 7 +++++--
 .../test/java/org/apache/brooklyn/util/net/UrlsTest.java    | 9 ++++++++-
 2 files changed, 13 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3db19cfd/utils/common/src/main/java/org/apache/brooklyn/util/net/Urls.java
----------------------------------------------------------------------
diff --git a/utils/common/src/main/java/org/apache/brooklyn/util/net/Urls.java b/utils/common/src/main/java/org/apache/brooklyn/util/net/Urls.java
index 84850bf..717e8a2 100644
--- a/utils/common/src/main/java/org/apache/brooklyn/util/net/Urls.java
+++ b/utils/common/src/main/java/org/apache/brooklyn/util/net/Urls.java
@@ -136,8 +136,11 @@ public class Urls {
                 }
                 return true;
             }
-            if (!Character.isAlphabetic(c) && c!='+') {
-                // only letters, numbers and + allowed before colon
+            
+            // protocol schema as per https://en.wikipedia.org/wiki/Uniform_Resource_Locator
+            if (i==0) {
+                if (!Character.isLetter(c)) return false;
+            } else if (!Character.isAlphabetic(c) && !Character.isDigit(c) &&
c!='+' && c!='.' && c!='-') {
                 return false; 
             }
         }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/3db19cfd/utils/common/src/test/java/org/apache/brooklyn/util/net/UrlsTest.java
----------------------------------------------------------------------
diff --git a/utils/common/src/test/java/org/apache/brooklyn/util/net/UrlsTest.java b/utils/common/src/test/java/org/apache/brooklyn/util/net/UrlsTest.java
index d5851e5..f775826 100644
--- a/utils/common/src/test/java/org/apache/brooklyn/util/net/UrlsTest.java
+++ b/utils/common/src/test/java/org/apache/brooklyn/util/net/UrlsTest.java
@@ -55,12 +55,19 @@ public class UrlsTest {
 
     @Test
     public void testIsUrlWithProtocol() {
+        Assert.assertTrue(Urls.isUrlWithProtocol("a1+b.c-d:/"));
         Assert.assertTrue(Urls.isUrlWithProtocol("http://localhost/"));
-        Assert.assertTrue(Urls.isUrlWithProtocol("protocol:"));
+        Assert.assertTrue(Urls.isUrlWithProtocol("protocol:xxx"));
         Assert.assertFalse(Urls.isUrlWithProtocol("protocol"));
         Assert.assertFalse(Urls.isUrlWithProtocol(":/"));
         Assert.assertFalse(Urls.isUrlWithProtocol("1:/"));
+        Assert.assertTrue(Urls.isUrlWithProtocol("a1+b.c-:those/chars/are/allowed/in/protocol"));
         Assert.assertFalse(Urls.isUrlWithProtocol(null));
+        Assert.assertTrue(Urls.isUrlWithProtocol("protocol:we allow spaces and %13 percent
chars"));
+        Assert.assertFalse(Urls.isUrlWithProtocol("protocol:we allow spaces\nbut not new
lines"));
+        Assert.assertFalse(Urls.isUrlWithProtocol("protocol: no space immediately after colon
though"));
+        Assert.assertFalse(Urls.isUrlWithProtocol("protocol:"));
+        Assert.assertFalse(Urls.isUrlWithProtocol("protocol_underscore_disallowed:"));
     }
 
     @Test


Mime
View raw message