From 73f992b7c90e7296962e3442d4f13fc0706360a7 Mon Sep 17 00:00:00 2001 From: konradoboza Date: Tue, 17 Mar 2020 09:17:26 +0100 Subject: [PATCH 1/3] EZEE-3030: Links containing 'ezlocation` or 'ezcontent' keywords break RTE validation on paste --- .../scripts/fieldType/base/base-rich-text.js | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js b/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js index 9bc8bbd58c..a04cc09e4a 100644 --- a/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js +++ b/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js @@ -398,18 +398,40 @@ const links = container.querySelectorAll('a'); const anchorPrefix = '#'; const protocolPrefix = 'http://'; + const restrictedKeywords = ['ezcontent', 'ezlocation']; links.forEach((link) => { const href = link.getAttribute('href'); const protocolPattern = /^https?:\/\//i; + const protocolHref = protocolPrefix.concat(href); - if (href && href.indexOf(anchorPrefix) !== 0 && !protocolPattern.test(href)) { - const protocolHref = protocolPrefix.concat(href); + if (!href && href.indexOf(anchorPrefix) === 0) { + return; + } + + if (protocolPattern.test(href)) { + return; + } + + if (this.containsAny(href, restrictedKeywords)) { + return; + } - link.setAttribute('href', protocolHref); - link.setAttribute('data-cke-saved-href', protocolHref); + link.setAttribute('href', protocolHref); + link.setAttribute('data-cke-saved-href', protocolHref); + }); + } + + containsAny(string, substrings) { + let isSubstringPresent = false; + + substrings.forEach((substring) => { + if (string.includes(substring)) { + isSubstringPresent = true; } }); + + return isSubstringPresent; } }; From 1e99acc1ee158b50860f3550547cd10337ef8424 Mon Sep 17 00:00:00 2001 From: konradoboza Date: Tue, 17 Mar 2020 11:02:08 +0100 Subject: [PATCH 2/3] changed keywords condition to use Array.some --- .../scripts/fieldType/base/base-rich-text.js | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js b/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js index a04cc09e4a..234a3762ec 100644 --- a/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js +++ b/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js @@ -405,7 +405,11 @@ const protocolPattern = /^https?:\/\//i; const protocolHref = protocolPrefix.concat(href); - if (!href && href.indexOf(anchorPrefix) === 0) { + if (!href) { + return; + } + + if (href.indexOf(anchorPrefix) === 0) { return; } @@ -413,7 +417,7 @@ return; } - if (this.containsAny(href, restrictedKeywords)) { + if (restrictedKeywords.some(keyword => href.includes(keyword))) { return; } @@ -421,18 +425,6 @@ link.setAttribute('data-cke-saved-href', protocolHref); }); } - - containsAny(string, substrings) { - let isSubstringPresent = false; - - substrings.forEach((substring) => { - if (string.includes(substring)) { - isSubstringPresent = true; - } - }); - - return isSubstringPresent; - } }; eZ.BaseRichText = BaseRichText; From c98f6386868d38bb294cefeb6cb7ac2fe1efd874 Mon Sep 17 00:00:00 2001 From: Konrad Oboza <34310128+konradoboza@users.noreply.github.com> Date: Tue, 17 Mar 2020 11:10:31 +0100 Subject: [PATCH 3/3] Update src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js Co-Authored-By: Dariusz Szut --- .../public/js/scripts/fieldType/base/base-rich-text.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js b/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js index 234a3762ec..dbe15db350 100644 --- a/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js +++ b/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js @@ -417,7 +417,7 @@ return; } - if (restrictedKeywords.some(keyword => href.includes(keyword))) { + if (restrictedKeywords.some((keyword) => href.includes(keyword))) { return; }