[Pkg-javascript-commits] [sockjs-client] 358/434: Fix #50 - fix bug in the isSameOriginUrl method
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:25 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 d628d4c1a347c738eb41769d651e9d1c45a9553c
Author: Marek Majkowski <majek04 at gmail.com>
Date: Wed Feb 29 15:51:45 2012 +0000
Fix #50 - fix bug in the isSameOriginUrl method
---
lib/utils.js | 12 +++++++-----
tests/html/src/unittests.coffee | 18 ++++++++++++++++++
2 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/lib/utils.js b/lib/utils.js
index fdd4df0..ad1674b 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -23,11 +23,13 @@ utils.getOrigin = function(url) {
return parts.join('/');
};
-utils.isSameOriginUrl = function(url) {
- // location.origin would do, but it's not available in some
- // browsers.
- var o = _window.location.href.split('/').slice(0,3).join('/');
- return url.slice(0, o.length) === o;
+utils.isSameOriginUrl = function(url_a, url_b) {
+ // location.origin would do, but it's not always available.
+ if (!url_b) url_b = _window.location.href;
+
+ return (url_a.split('/').slice(0,3).join('/')
+ ===
+ url_b.split('/').slice(0,3).join('/'));
};
utils.getParentDomain = function(url) {
diff --git a/tests/html/src/unittests.coffee b/tests/html/src/unittests.coffee
index a54872f..b33b9fa 100644
--- a/tests/html/src/unittests.coffee
+++ b/tests/html/src/unittests.coffee
@@ -21,6 +21,24 @@ 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 'isSameOriginUrl', ->
+ ok(u.isSameOriginUrl('http://localhost', 'http://localhost/'))
+ ok(u.isSameOriginUrl('http://localhost', 'http://localhost/abc'))
+ ok(u.isSameOriginUrl('http://localhost/', 'http://localhost'))
+ ok(u.isSameOriginUrl('http://localhost', 'http://localhost'))
+ ok(u.isSameOriginUrl('http://localhost', 'http://localhost:8080') is false)
+ ok(u.isSameOriginUrl('http://localhost:8080', 'http://localhost') is false)
+ ok(u.isSameOriginUrl('http://localhost:8080', 'http://localhost:8080/'))
+ ok(u.isSameOriginUrl('http://127.0.0.1:80/', 'http://127.0.0.1:80/a'))
+ ok(u.isSameOriginUrl('http://127.0.0.1:80', 'http://127.0.0.1:80/a'))
+ ok(u.isSameOriginUrl('http://localhost', 'http://localhost:80') is false)
+ ok(u.isSameOriginUrl('http://127.0.0.1/', 'http://127.0.0.1:80/a') is false)
+ ok(u.isSameOriginUrl('http://127.0.0.1:9', 'http://127.0.0.1:9999') is false)
+ ok(u.isSameOriginUrl('http://127.0.0.1:99', 'http://127.0.0.1:9999') is false)
+ ok(u.isSameOriginUrl('http://127.0.0.1:999', 'http://127.0.0.1:9999') is false)
+ ok(u.isSameOriginUrl('http://127.0.0.1:9999', 'http://127.0.0.1:9999'))
+ ok(u.isSameOriginUrl('http://127.0.0.1:99999', 'http://127.0.0.1:9999') is false)
+
test "getParentDomain", ->
domains =
'localhost': 'localhost'
--
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