[Pkg-javascript-commits] [sockjs-client] 83/434: Accept urls starting with '//' or '/'
Tonnerre Lombard
tonnerre-guest at moszumanska.debian.org
Wed Jan 8 00:47:04 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 7e3f2d9b5384cc5276b39a85ab1f85e85238389e
Author: Marek Majkowski <majek04 at gmail.com>
Date: Tue Aug 16 14:16:11 2011 +0100
Accept urls starting with '//' or '/'
---
lib/sockjs.js | 2 +-
lib/utils.js | 13 +++++++++++++
tests/html/src/tests.coffee | 17 +++++++++++++++++
3 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/lib/sockjs.js b/lib/sockjs.js
index a55aaf5..f2319c6 100644
--- a/lib/sockjs.js
+++ b/lib/sockjs.js
@@ -4,7 +4,7 @@ var SockJS = function(url, protocols, options) {
if (options) {
utils.objectExtend(that._options, options);
}
- that._base_url = url;
+ that._base_url = utils.amendUrl(url);
that._server = that._options.server || utils.random_number_string(1000);
that._connid = utils.random_string(8);
that._trans_url = that._base_url + '/' + that._server + '/' + that._connid;
diff --git a/lib/utils.js b/lib/utils.js
index 0c96fac..c7ff1bf 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -262,3 +262,16 @@ utils.bind = function(fun, that) {
};
}
};
+
+utils.amendUrl = function(url) {
+ var dl = _document.location;
+ // '//abc' --> 'http://abc'
+ if (url.indexOf('//') === 0) {
+ url = dl.protocol + url;
+ }
+ // '/abc' --> 'http://localhost:80/abc'
+ if (url.indexOf('/') === 0) {
+ url = dl.protocol + '//' + dl.host + url;
+ }
+ return url;
+};
diff --git a/tests/html/src/tests.coffee b/tests/html/src/tests.coffee
index 39ac9b6..8f2eb44 100644
--- a/tests/html/src/tests.coffee
+++ b/tests/html/src/tests.coffee
@@ -228,3 +228,20 @@ protocols = ['websocket',
'jsonp-polling']
for protocol in protocols
test_protocol(protocol)
+
+
+
+
+module('other')
+
+test "amending url", ->
+ dl = document.location
+
+ r = new SockJS('//blah:1/abc', [])
+ equal(r._base_url, dl.protocol + '//blah:1/abc')
+
+ r = new SockJS('/abc', [])
+ equal(r._base_url, dl.protocol + '//' + dl.host + '/abc')
+
+ r = new SockJS('http://a:1/abc', [])
+ equal(r._base_url, 'http://a:1/abc')
--
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