From 034e525c2662ab30bf9e48da41ba3aa9704d84bb Mon Sep 17 00:00:00 2001 From: konradoboza Date: Wed, 19 Feb 2020 10:41:29 +0100 Subject: [PATCH 1/2] EZP-31371: Copying a web page link w/o protocol in a Word paragraph leads to a 404 error --- .../scripts/fieldType/base/base-rich-text.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) 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 b9793d3a34..f7f5cf55f9 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 @@ -325,6 +325,11 @@ nativeEditor.on('change', saveRichText); nativeEditor.on('customUpdate', saveRichText); nativeEditor.on('editorInteraction', saveRichText); + nativeEditor.on('paste', () => { + setTimeout(() => { + this.setLinksProtocol(container); + }); + }); return alloyEditor; } @@ -390,6 +395,24 @@ splitIntoWords(text) { return text.split(' ').filter((word) => word.trim()); } + + setLinksProtocol(container) { + const links = container.querySelectorAll('a'); + const anchorPrefix = '#'; + const protocolPrefix = 'http://'; + + links.forEach((link) => { + const href = link.getAttribute('href'); + const protocolPattern = /^https?:\/\//i; + + if (href && href.indexOf(anchorPrefix) !== 0 && !protocolPattern.test(href)) { + const protocolHref = protocolPrefix.concat(href); + + link.setAttribute('href', protocolHref); + link.setAttribute('data-cke-saved-href', protocolHref); + } + }); + } }; eZ.BaseRichText = BaseRichText; From f8b36ca428a8d358d9712dec4abf149a21934613 Mon Sep 17 00:00:00 2001 From: konradoboza Date: Wed, 19 Feb 2020 11:48:06 +0100 Subject: [PATCH 2/2] changed event to CKEditor's afterPaste --- .../public/js/scripts/fieldType/base/base-rich-text.js | 6 ++---- 1 file changed, 2 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 f7f5cf55f9..9bc8bbd58c 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 @@ -325,10 +325,8 @@ nativeEditor.on('change', saveRichText); nativeEditor.on('customUpdate', saveRichText); nativeEditor.on('editorInteraction', saveRichText); - nativeEditor.on('paste', () => { - setTimeout(() => { - this.setLinksProtocol(container); - }); + nativeEditor.on('afterPaste', () => { + this.setLinksProtocol(container); }); return alloyEditor;