From 6bc057394b2b8ad310f403f0b4571301fe0e5d60 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Thu, 3 Nov 2022 13:13:44 +0000 Subject: [PATCH] [FIX] web_editor: prevent zws in url on paste Paste a url in the editor from the URL bar of the browser. If you then select it all and paste another URL in its stead, the zws inserted by the sanitizer when deleting the selection ends up in the URL. This is because the sanitizer moves downward into the DOM tree, therefore change the link URL before removing the zws in its text child node. To make sure this can't ever happen, we now remove zws from URLs when parsing them from the link's text content. task-3054233 closes odoo/odoo#105045 X-original-commit: c4c9627297c0e3e3977cbfd51129227f8ec1ce3c Signed-off-by: David Monjoie (dmo) --- .../src/js/editor/odoo-editor/src/utils/sanitize.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/sanitize.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/sanitize.js index d0162e6d1fb..77307dec78d 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/sanitize.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/sanitize.js @@ -220,7 +220,10 @@ class Sanitize { ) { node.setAttribute('contenteditable', 'false'); } - // update link URL if label is a new valid link + if (node.firstChild) { + this._parse(node.firstChild); + } + // Update link URL if label is a new valid link. if (node.nodeName === 'A' && anchorEl === node) { const linkLabel = node.textContent; const match = linkLabel.match(URL_REGEX); @@ -229,9 +232,6 @@ class Sanitize { node.setAttribute('href', urlInfo.url); } } - if (node.firstChild) { - this._parse(node.firstChild); - } node = node.nextSibling; }