From 02add8e5decfd322d6f2cf2c9607648836adc0ba Mon Sep 17 00:00:00 2001 From: Rodolpho Lima Date: Wed, 26 Apr 2023 11:41:59 +0200 Subject: [PATCH] [FIX] web_editor: auto transforming email URL Typing a URL + SPACE transforms the URL into a link. Before this commit, email URLs were incorrectly prepended with 'https://'. Because it is not desirable to automatically transform email URLs, this commit disables link transformation for email URLs, leaving it only active for http URLs. task-3284649 X-original-commit: ad0e7845fceb578398e42e4b35820c415734452a Part-of: odoo/odoo#136278 --- .../js/editor/odoo-editor/src/OdooEditor.js | 3 ++- .../odoo-editor/test/spec/editor.test.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js index 1c3a4ce4ad2..b4909606a2f 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js @@ -78,6 +78,7 @@ import { leftPos, isNotAllowedContent, childNodeIndex, + EMAIL_REGEX, } from './utils/utils.js'; import { editorCommands } from './commands/commands.js'; import { Powerbox } from './powerbox/Powerbox.js'; @@ -4589,7 +4590,7 @@ export class OdooEditor extends EventTarget { const textSliced = selection.anchorNode.textContent.slice(0, selection.anchorOffset); const textNodeSplitted = textSliced.split(/\s/); let potentialUrl = textNodeSplitted.pop(); - const lastWordMatch = potentialUrl.match(URL_REGEX_WITH_INFOS); + const lastWordMatch = potentialUrl.match(URL_REGEX_WITH_INFOS) && !potentialUrl.match(EMAIL_REGEX); if (lastWordMatch) { const matches = getUrlsInfosInString(textSliced); diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js index a10dfd79a9e..3408fa6f820 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/editor.test.js @@ -4250,6 +4250,25 @@ X[] contentAfter: '

a http://test.com b http://test.com
[] c http://test.com d

', }); }); + it('should not transform an email url after space', async () => { + await testEditor(BasicEditor, { + contentBefore: '

user@domain.com[]

', + stepFunction: async (editor) => { + editor.testMode = false; + const selection = document.getSelection(); + const anchorOffset = selection.anchorOffset; + const p = editor.editable.querySelector('p'); + const textNode = p.childNodes[0]; + triggerEvent(editor.editable, 'keydown', {key: ' ', code: 'Space'}); + textNode.textContent = "user@domain.com\u00a0"; + selection.extend(textNode, anchorOffset + 1); + selection.collapseToEnd(); + triggerEvent(editor.editable, 'input', {data: ' ', inputType: 'insertText' }); + triggerEvent(editor.editable, 'keyup', {key: ' ', code: 'Space'}); + }, + contentAfter: '

user@domain.com []

', + }); + }); it('should not transform url after two space', async () => { await testEditor(BasicEditor, { contentBefore: '

a http://test.com b http://test.com [] c http://test.com d

',