[Pkg-javascript-commits] [sockjs-client] 340/434: add getParentDomain() helper

Tonnerre Lombard tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:23 UTC 2014


This is an automated email from the git hooks/post-receive script.

tonnerre-guest pushed a commit to branch master
in repository sockjs-client.

commit 0b3f6c99756b4cbd35853089954fff14c83bc1b7
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Wed Feb 1 10:54:07 2012 +0000

    add getParentDomain() helper
---
 lib/utils.js                    | 12 ++++++++++++
 tests/html/src/unittests.coffee | 13 +++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/lib/utils.js b/lib/utils.js
index 865ce53..fdd4df0 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -30,6 +30,18 @@ utils.isSameOriginUrl = function(url) {
     return url.slice(0, o.length) === o;
 };
 
+utils.getParentDomain = function(url) {
+    // ipv4 ip address
+    if (/^[0-9.]*$/.test(url)) return url;
+    // ipv6 ip address
+    if (/^\[/.test(url)) return url;
+    // no dots
+    if (!(/[.]/.test(url))) return url;
+
+    var parts = url.split('.').slice(1);
+    return parts.join('.');
+};
+
 utils.objectExtend = function(dst, src) {
     for(var k in src) {
         if (src.hasOwnProperty(k)) {
diff --git a/tests/html/src/unittests.coffee b/tests/html/src/unittests.coffee
index 5fd4ba1..a54872f 100644
--- a/tests/html/src/unittests.coffee
+++ b/tests/html/src/unittests.coffee
@@ -21,6 +21,19 @@ test 'getOrigin', ->
     equal(u.getOrigin('http://a.b/c'), 'http://a.b')
     equal(u.getOrigin('http://a.b:123/c'), 'http://a.b:123')
 
+test "getParentDomain", ->
+    domains =
+        'localhost': 'localhost'
+        '127.0.0.1': '127.0.0.1'
+        'a.b.c.d':   'b.c.d'
+        'a.b.c.d.e': 'b.c.d.e'
+        '[::1]':     '[::1]'
+        'a.org':     'org'
+        'a2.a3.org': 'a3.org'
+
+    for k of domains
+        equal(u.getParentDomain(k), domains[k])
+
 test 'objectExtend', ->
     deepEqual(u.objectExtend({}, {}), {})
     a = {a:1};

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/sockjs-client.git



More information about the Pkg-javascript-commits mailing list