From e76459bc0eef85e263ce1313cc4f370d7fe4fbf2 Mon Sep 17 00:00:00 2001 From: Rodolpho Lima Date: Wed, 7 Jun 2023 09:38:31 +0000 Subject: [PATCH] [FIX] web_editor: link with @ open new window option Before this commit, when using the LinkTools (website, mass_mailing), if an http URL contained a "@" (ex: https://www.youtube.com/@iRopes), it got incorrectly recognized as an e-mail URL and the option to open the link in a new windown was hidden from the UI. This commit fixes the issue by making the test for e-mail URL slightly more robust than just checking for the presence of a "@". task-3356685 opw-3349704 closes odoo/odoo#125742 X-original-commit: 3f1db2397e50b26e2658d270cbb7ce908d5c05cd Signed-off-by: David Monjoie (dmo) --- .../static/src/js/editor/odoo-editor/src/utils/utils.js | 1 + addons/web_editor/static/src/js/wysiwyg/widgets/link.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) 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 06679a20dff..9da0f6c79dd 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 @@ -55,6 +55,7 @@ export const URL_REGEX = new RegExp(`((?:(?:${httpRegex}${urlRegexBase}))`, 'gi' export const URL_REGEX_WITH_INFOS = new RegExp(`((?:(?:${httpCapturedRegex}${urlRegexBase}))`, 'gi'); export const YOUTUBE_URL_GET_VIDEO_ID = /^(?:(?:https?:)?\/\/)?(?:(?:www|m)\.)?(?:youtube\.com|youtu\.be)(?:\/(?:[\w-]+\?v=|embed\/|v\/)?)([^\s?&#]+)(?:\S+)?$/i; +export const EMAIL_REGEX = /^(mailto:)?[\w-.]+@(?:[\w-]+\.)+[\w-]{2,4}$/i; //------------------------------------------------------------------------------ // Position and sizes diff --git a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js index 7afd64b59d2..6f10767ed41 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js @@ -7,6 +7,7 @@ import {isColorGradient} from "web_editor.utils"; const getDeepRange = OdooEditorLib.getDeepRange; const getInSelection = OdooEditorLib.getInSelection; +const EMAIL_REGEX = OdooEditorLib.EMAIL_REGEX; const _t = core._t; /** @@ -568,7 +569,7 @@ const Link = Widget.extend({ this._savedURLInputOnDestroy = true; var $linkUrlInput = this.$('#o_link_dialog_url_input'); let value = $linkUrlInput.val(); - let isLink = value.indexOf('@') < 0; + let isLink = !EMAIL_REGEX.test(value); this._getIsNewWindowFormRow().toggleClass('d-none', !isLink); this.$('.o_strip_domain').toggleClass('d-none', value.indexOf(window.location.origin) !== 0); },