Commit 47df00be authored by Georgi Mateev's avatar Georgi Mateev
Browse files

[TASK] #138 Do not mark externall adresses as external content

parent 976a38d2
......@@ -812,6 +812,10 @@ var SgCookieOptin = {
return false;
}
if (SgCookieOptin.isUrlLocal(externalContent.getAttribute(attribute))) {
return true;
}
for (var regExIndex in regularExpressions) {
if (typeof externalContent.getAttribute === 'function' && regularExpressions[regExIndex].test(externalContent.getAttribute(attribute))) {
return true;
......@@ -833,14 +837,23 @@ var SgCookieOptin = {
}
var sources = externalContent.querySelectorAll('source');
var foundNonWhitelisted = false;
for (var sourceIndex in sources) {
if (!sources.hasOwnProperty(sourceIndex)) {
continue;
}
if (!sources[sourceIndex].getAttribute('src')) {
continue;
}
// noinspection JSUnfilteredForInLoop
if (SgCookieOptin.isElementWhitelisted(sources[sourceIndex], 'src', regularExpressions)) {
return true;
if (!SgCookieOptin.isElementWhitelisted(sources[sourceIndex], 'src', regularExpressions)) {
foundNonWhitelisted = true;
}
}
return false;
return !foundNonWhitelisted;
},
/**
......@@ -858,6 +871,16 @@ var SgCookieOptin = {
return false;
},
/**
* Checks if the given URL is a local or relative path
* @param {string} url
*/
isUrlLocal: function(url) {
var tempA = document.createElement('a');
tempA.setAttribute('href', url);
return window.location.protocol === tempA.protocol && window.location.host === tempA.host;
},
/**
* Adds a consent for externalContents, which needs to be accepted.
*
......@@ -1350,6 +1373,9 @@ var SgCookieOptin = {
}
},
/**
* Polyfill for the Element.matches and Element.closest
*/
closestPolyfill: function() {
const ElementPrototype = window.Element.prototype;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment