Skip to content

Commit

Permalink
Merge pull request #722 from AnalyticalGraphicsInc/fix_isCrossOriginU…
Browse files Browse the repository at this point in the history
…rl_in_ie

Fix isCrossOriginUrl in IE
  • Loading branch information
mramato committed Apr 30, 2013

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 3cf39a7 + 223241a commit 58fb2e2
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions Source/Core/isCrossOriginUrl.js
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ define(function() {

var location = window.location;
a.href = url;
a.href = a.href; // IE only absolutizes href on get, not set

// host includes both hostname and port if the port is not standard
return a.protocol !== location.protocol || a.host !== location.host;
43 changes: 43 additions & 0 deletions Specs/Core/isCrossOriginUrlSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*global defineSuite*/
defineSuite([
'Core/isCrossOriginUrl',
'ThirdParty/Uri'
], function(
isCrossOriginUrl,
Uri) {
"use strict";
/*global jasmine,describe,xdescribe,it,xit,expect,beforeEach,afterEach,beforeAll,afterAll,spyOn,runs,waits,waitsFor*/

it('returns false for relative urls', function() {
expect(isCrossOriginUrl('/some/url.jpg')).toEqual(false);
expect(isCrossOriginUrl('some/url.jpg')).toEqual(false);
});

it('returns false for absolute urls that are not cross-origin', function() {
var pageUri = new Uri(location.href);

var absoluteUrl = new Uri('/some/url.jpg').resolve(pageUri).toString();
expect(isCrossOriginUrl(absoluteUrl)).toEqual(false);

absoluteUrl = new Uri('some/url.jpg').resolve(pageUri).toString();
expect(isCrossOriginUrl(absoluteUrl)).toEqual(false);
});

it('returns true for absolute urls that are cross-origin', function() {
expect(isCrossOriginUrl('http://example.com/some/url.jpg')).toEqual(true);

// a different scheme counts as cross-origin
var pageUri = new Uri(location.href);
pageUri.scheme = location.protocol === 'https:' ? 'http' : 'https';

var absoluteUrl = pageUri.toString();
expect(isCrossOriginUrl(absoluteUrl)).toEqual(true);

// so does a different port
pageUri = new Uri(location.href);
pageUri.authority = location.hostname + ':' + (+location.port + 1);

absoluteUrl = pageUri.toString();
expect(isCrossOriginUrl(absoluteUrl)).toEqual(true);
});
});

0 comments on commit 58fb2e2

Please sign in to comment.