[Pkg-javascript-commits] [sockjs-client] 10/22: Fix #74 - remove explicit port numbers from sockjs urls when not necessary (thanks to @nicholasbs)

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


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

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

commit 3f7e5f4ef5673dc15d3d3db890bc82a725f0c91d
Author: Marek Majkowski <majek04 at gmail.com>
Date:   Thu Jan 10 15:51:49 2013 +0000

    Fix #74 - remove explicit port numbers from sockjs urls when not necessary (thanks to @nicholasbs)
---
 lib/utils.js                    | 12 +++++++++++-
 tests/html/src/unittests.coffee |  7 +++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/lib/utils.js b/lib/utils.js
index 0175944..80b5a77 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -122,12 +122,22 @@ utils.amendUrl = function(url) {
     if (url.indexOf('//') === 0) {
         url = dl.protocol + url;
     }
-    // '/abc' --> 'http://localhost:80/abc'
+    // '/abc' --> 'http://localhost:1234/abc'
     if (url.indexOf('/') === 0) {
         url = dl.protocol + '//' + dl.host + url;
     }
     // strip trailing slashes
     url = url.replace(/[/]+$/,'');
+
+    // We have a full url here, with proto and host. For some browsers
+    // http://localhost:80/ is not in the same origin as http://localhost/
+	// Remove explicit :80 or :443 in such cases. See #74
+    var parts = url.split("/");
+    if ((parts[0] === "http:" && /:80$/.test(parts[2])) ||
+	    (parts[0] === "https:" && /:443$/.test(parts[2]))) {
+		parts[2] = parts[2].replace(/:(80|443)$/, "");
+	}
+    url = parts.join("/");
     return url;
 };
 
diff --git a/tests/html/src/unittests.coffee b/tests/html/src/unittests.coffee
index 7202099..cf7b340 100644
--- a/tests/html/src/unittests.coffee
+++ b/tests/html/src/unittests.coffee
@@ -88,6 +88,13 @@ test 'amendUrl', ->
     t = -> u.amendUrl('http://abc#a')
     raises(t, 'Only basic urls are supported')
 
+    # For some browsers http://localhost:80/ is not in the same origin
+    # as http://localhost/. Remove explicit port number in such cases. See #74
+    equal(u.amendUrl('http://a:80/abc'), 'http://a/abc')
+    equal(u.amendUrl('https://a:443/abc'), 'https://a/abc')
+    equal(u.amendUrl('https://a:80/abc'), 'https://a:80/abc')
+    equal(u.amendUrl('http://a:443/abc'), 'http://a:443/abc')
+
 test 'arrIndexOf', ->
     a = [1,2,3,4,5]
     equal(u.arrIndexOf(a, 1), 0)

-- 
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