Skip to content

Commit

Permalink
Normalize IE9 URL parsing. Fix for videojs#1764
Browse files Browse the repository at this point in the history
IE9 appends the port number to the host property of anchor tags on http pages. Strip the port for http and https so that it behaves like everyone else.
  • Loading branch information
dmlap committed Dec 22, 2014
1 parent a048468 commit b45bf98
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/js/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,15 @@ vjs.parseUrl = function(url) {
details[props[i]] = a[props[i]];
}

// IE9 adds the port to the host property unlike everyone else. If
// a port identifier is added for standard ports, strip it.
if (details.protocol === 'http:') {
details.host = details.host.replace(/:80$/, '');
}
if (details.protocol === 'https:') {
details.host = details.host.replace(/:443$/, '');
}

if (addToBody) {
document.body.removeChild(div);
}
Expand Down
32 changes: 31 additions & 1 deletion test/unit/lib.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
module('Lib');
var createElement;

module('Lib', {
setup: function() {
createElement = document.createElement;
},
teardown: function() {
document.createElement = createElement;
}
});

test('should create an element', function(){
var div = vjs.createEl();
Expand Down Expand Up @@ -282,6 +291,27 @@ test('should parse the details of a url correctly', function(){
equal(vjs.parseUrl('http://example.com:1234').port, '1234', 'parsed example url port');
});

test('should strip port from hosts using http or https', function() {
var url;

// attempts to create elements will return an anchor tag that
// misbehaves like IE9
document.createElement = function() {
return {
hostname: 'example.com',
host: 'example.com:80',
protocol: 'http:',
port: '80',
pathname: '/domain/relative/url',
hash: ''
};
};

url = videojs.parseUrl('/domain/relative/url');
ok(!(/.*:80$/).test(url.host), ':80 is not appended to the host');
});


test('vjs.findPosition should find top and left position', function() {
var d = document.createElement('div'),
position = vjs.findPosition(d);
Expand Down

0 comments on commit b45bf98

Please sign in to comment.