[Pkg-javascript-commits] [sockjs-client] 54/350: Handle origin with port numbers correctly
tonnerre at ancient-solutions.com
tonnerre at ancient-solutions.com
Fri Aug 5 01:03:41 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 5d6010865a233edbc7622f103744ba5f95d05d67
Author: Paweł Ledwoń <me at ludvik.pl>
Date: Fri Mar 8 16:07:29 2013 +0000
Handle origin with port numbers correctly
---
lib/trans-iframe.js | 3 ++-
lib/utils.js | 23 +++++++++++++++++------
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/lib/trans-iframe.js b/lib/trans-iframe.js
index ec1fd09..d96ef6d 100644
--- a/lib/trans-iframe.js
+++ b/lib/trans-iframe.js
@@ -55,7 +55,8 @@ IframeTransport.prototype.doCleanup = function() {
IframeTransport.prototype.onmessage = function(e) {
var that = this;
- if (e.origin !== that.origin) return;
+
+ if (!utils.isSameOriginUrl(e.origin, that.origin)) return;
var window_id = e.data.slice(0, 8);
var type = e.data.slice(8, 9);
var data = e.data.slice(9);
diff --git a/lib/utils.js b/lib/utils.js
index 49ae47c..2e4efff 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -43,18 +43,29 @@ utils.random_number_string = function(max) {
// Assuming that url looks like: http://asdasd:111/asd
utils.getOrigin = function(url) {
- url += '/';
- var parts = url.split('/').slice(0, 3);
- return parts.join('/');
+ var parts = url.split('/');
+ var protocol = parts[0];
+ var host = parts[2];
+ var atSignIndex = host.lastIndexOf('@');
+ var hostname;
+ var port;
+
+ if (~atSignIndex) host = host.slice(atSignIndex + 1);
+
+ parts = host.split(':');
+ hostname = parts[0];
+ port = parts[1];
+
+ if (!port) port = (protocol === 'https:') ? 443 : 80;
+
+ return protocol + '//' + hostname + ':' + port;
};
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('/'));
+ return utils.getOrigin(url_a) === utils.getOrigin(url_b);
};
utils.isSameOriginScheme = function(url_a, url_b) {
--
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