Skip to content

Commit

Permalink
Merge pull request #4 from sovrn/enhanced-location-detection
Browse files Browse the repository at this point in the history
CR for enhanced-location-detection PR
  • Loading branch information
rachelrj authored Mar 1, 2018
2 parents 74ed7f9 + 1269a33 commit 55284d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function parse(url, options) {
parsed.href = decodeURIComponent(url);
}
return {
href: parsed.href,
protocol: (parsed.protocol || '').replace(/:$/, ''),
hostname: parsed.hostname,
port: +parsed.port,
Expand Down
11 changes: 5 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { config } from './config';
import clone from 'just-clone';
import find from 'core-js/library/fn/array/find';
import includes from 'core-js/library/fn/array/includes';
import { parse } from './url';

var CONSTANTS = require('./constants');

var _loggingChecked = false;
Expand Down Expand Up @@ -175,10 +177,12 @@ const getIframeParentLoc = function() {
window.document.location.ancestorOrigins.length >= 1) {
loc = window.document.location.ancestorOrigins[window.document.location.ancestorOrigins.length - 1];
} else if (window.document.location) {
// force an exception in x-domain environments. #1509
window.top.location.toString();
loc = getNonWebKitIframeParentLoc();
}
}
loc = parseFullUrl(loc);
loc = parse(loc);
} catch (e) {
this.logMessage('getTopParentLoc failure', e);
}
Expand All @@ -198,11 +202,6 @@ const getNonWebKitIframeParentLoc = function() {
return referrerLoc;
};

const parseFullUrl = function(locString) {
const match = locString.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)([\/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
return match && {protocol: match[1], host: match[2], hostname: match[3], port: match[4], pathname: match[5], search: match[6], hash: match[7], href: match.input};
};

exports.getTopWindowUrl = function () {
let href;
try {
Expand Down

0 comments on commit 55284d5

Please sign in to comment.