[Pkg-javascript-commits] [sockjs-client] 149/350: Handle location.origin not being available in IE6

tonnerre at ancient-solutions.com tonnerre at ancient-solutions.com
Fri Aug 5 01:03:56 UTC 2016


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 ba239c3d23742f20c9d72224c7f209109bc4d3cc
Author: Bryce Kahle <bkahle at gmail.com>
Date:   Thu Oct 16 18:01:16 2014 -0400

    Handle location.origin not being available in IE6
---
 lib/main.js             | 3 ++-
 lib/utils/origin.js     | 5 ++++-
 tests/lib/test-utils.js | 3 ++-
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/lib/main.js b/lib/main.js
index 814cdf2..acdba80 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -80,7 +80,8 @@ function SockJS(url, protocols, transportsWhitelist) {
   });
 
   // Step 6 - convert origin
-  this._origin = loc.origin ? loc.origin.toLowerCase() : null;
+  var o = origin.getOrigin(loc.href);
+  this._origin = o ? o.toLowerCase() : null;
 
   // strip port numbers for 80 and 443 cases
   // Issue #74
diff --git a/lib/utils/origin.js b/lib/utils/origin.js
index 6aa216a..4501da7 100644
--- a/lib/utils/origin.js
+++ b/lib/utils/origin.js
@@ -4,6 +4,10 @@ var u = require('url');
 
 module.exports = {
   getOrigin: function (url) {
+    if (!url) {
+      return null;
+    }
+
     var p = u.parse(url);
     if (p.protocol === 'file:') {
       return null;
@@ -18,7 +22,6 @@ module.exports = {
   }
 
 , isSameOriginUrl: function(urlA, urlB) {
-    // location.origin would do, but it's not always available.
     return this.getOrigin(urlA) === this.getOrigin(urlB);
   }
 
diff --git a/tests/lib/test-utils.js b/tests/lib/test-utils.js
index 62c098d..669242d 100644
--- a/tests/lib/test-utils.js
+++ b/tests/lib/test-utils.js
@@ -2,6 +2,7 @@
 
 var SockJS = require('../../lib/entry')
   , iframeUtils = require('../../lib/utils/iframe')
+  , origin = require('../../lib/utils/origin')
   , random = require('../../lib/utils/random')
   ;
 
@@ -10,7 +11,7 @@ var MPrefix = '_sockjs_global';
 module.exports = {
   getOriginUrl: function () {
     if (global.location) {
-      return global.location.origin;
+      return origin.getOrigin(global.location.href);
     }
     return 'http://localhost:8081';
   }

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