From 82ba5791f042498ba7e69a56cc8968d2b5912baf Mon Sep 17 00:00:00 2001 From: Rodolpho Lima Date: Thu, 21 Sep 2023 18:54:41 +0200 Subject: [PATCH] [IMP] web_editor: unify behaviour for http protocol LinkTools creates http links by default, while OdooEditor creates https links by default on paste and auto link transformation with SPACE. This commit standardizes the result of both mechanisms, adopting "http" as the default protocol. task-3516854 closes odoo/odoo#136487 Signed-off-by: David Monjoie (dmo) --- .../static/src/js/editor/odoo-editor/src/OdooEditor.js | 4 ++-- .../src/js/editor/odoo-editor/src/utils/sanitize.js | 2 +- .../src/js/editor/odoo-editor/src/utils/utils.js | 2 +- .../js/editor/odoo-editor/test/spec/copyPaste.test.js | 10 +++++----- .../src/js/editor/odoo-editor/test/spec/link.test.js | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) 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 64f40889735..05f243e4fbe 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 @@ -4708,7 +4708,7 @@ export class OdooEditor extends EventTarget { } if (splitAroundUrl.length === 3 && !splitAroundUrl[0] && !splitAroundUrl[2]) { // Pasted content is a single URL. - const url = /^https?:\/\//i.test(text) ? text : 'https://' + text; + const url = /^https?:\/\//i.test(text) ? text : 'http://' + text; const youtubeUrl = this.options.allowCommandVideo &&YOUTUBE_URL_GET_VIDEO_ID.exec(url); const urlFileExtention = url.split('.').pop(); const isImageUrl = ['jpg', 'jpeg', 'png', 'gif', 'svg', 'webp'].includes(urlFileExtention.toLowerCase()); @@ -4802,7 +4802,7 @@ export class OdooEditor extends EventTarget { for (let i = 0; i < splitAroundUrl.length; i++) { const url = /^https?:\/\//gi.test(splitAroundUrl[i]) ? splitAroundUrl[i] - : 'https://' + splitAroundUrl[i]; + : 'http://' + splitAroundUrl[i]; // Even indexes will always be plain text, and odd indexes will always be URL. // A url cannot be transformed inside an existing link. if (i % 2 && !selectionIsInsideALink) { 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 5dba980e148..d5a7320c892 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 @@ -107,7 +107,7 @@ export function deduceURLfromText(text, link) { // Avoid converting a http link to https. return currentHttpProtocol + match[0]; } else { - return 'https://' + match[0]; + return 'http://' + match[0]; } } // Check for telephone url. diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js index f42a6754f80..f0ebed294eb 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js @@ -1527,7 +1527,7 @@ export function getUrlsInfosInString(string) { match; while ((match = URL_REGEX_WITH_INFOS.exec(string))) { infos.push({ - url: match[2] ? match[0] : 'https://' + match[0], + url: match[2] ? match[0] : 'http://' + match[0], label: match[0], index: match.index, length: match[0].length, diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js index f697cd3d90b..e739147acc8 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/copyPaste.test.js @@ -1473,15 +1473,15 @@ describe('Paste', () => { stepFunction: async editor => { await pasteText(editor, 'abc www.odoo.com xyz'); }, - contentAfter: '

abc www.odoo.com xyz[]

', + contentAfter: '

abc www.odoo.com xyz[]

', }); await testEditor(BasicEditor, { contentBefore: '

[]\u200B

', stepFunction: async editor => { await pasteText(editor, 'odoo.com\ngoogle.com'); }, - contentAfter: '

odoo.com

' + - '

google.com[]

' + contentAfter: '

odoo.com

' + + '

google.com[]

' }); }); it('should paste html content over an empty link', async () => { @@ -1687,14 +1687,14 @@ describe('Paste', () => { stepFunction: async editor => { await pasteText(editor, 'www.odoo.com'); }, - contentAfter: '

www.odoo.com[]

', + contentAfter: '

www.odoo.com[]

', }); await testEditor(BasicEditor, { contentBefore: '

[xyz]

', stepFunction: async editor => { await pasteText(editor, 'abc www.odoo.com xyz'); }, - contentAfter: '

abc www.odoo.com xyz[]

', + contentAfter: '

abc www.odoo.com xyz[]

', }); const imageUrl = 'https://download.odoocdn.com/icons/website/static/description/icon.png'; await testEditor(BasicEditor, { diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/link.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/link.test.js index 2dad1471ae9..627a5b173fc 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/link.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/link.test.js @@ -312,7 +312,7 @@ describe('Link', () => { stepFunction: async editor => { await deleteBackward(editor); }, - contentAfter: '

ahello[]moto.com

', + contentAfter: '

ahello[]moto.com

', }); }); it('should change the url in one step', async () => {