From b622dba6db8f7a1ac4474b2c6fa509b527f515bb Mon Sep 17 00:00:00 2001 From: Rodolpho Lima Date: Fri, 14 Apr 2023 19:05:35 +0200 Subject: [PATCH] [FIX] web_editor: 'mailto' to 'http' link conversion Before this commit: - URLs like "domain.com/@/page" were incorrectly detected as an email URL by Link(Dialog/Tools), - switching from an email URL to a http URL with the Link(Dialog/Tools) was not possible (URL remained prepended with "mailto:"). This commit improves email detection from simply looking for a "@" to something slightly more robust, and makes switching between 'http' and 'mailto' links possible. task-3284649 opw-3245501 X-original-commit: e849ff4333355386dfb79bc574c93c76ed3e2d3b Part-of: odoo/odoo#136278 --- .../static/src/js/wysiwyg/widgets/link.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) 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 91c0540bf76..1fa9cbd00c7 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/link.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/link.js @@ -240,12 +240,10 @@ export class Link extends Component { * @private */ _correctLink(url) { - if (url.indexOf('mailto:') === 0 || url.indexOf('tel:') === 0) { + if (url.indexOf('tel:') === 0) { url = url.replace(/^tel:([0-9]+)$/, 'tel://$1'); - } else if (url.indexOf('@') !== -1 && url.indexOf(':') === -1) { - url = 'mailto:' + url; - } else if (url && url.indexOf('://') === -1 && url[0] !== '/' - && url[0] !== '#' && url.slice(0, 2) !== '${') { + } else if (url && !url.startsWith('mailto:') && url.indexOf('://') === -1 + && url[0] !== '/' && url[0] !== '#' && url.slice(0, 2) !== '${') { url = 'http://' + url; } return url; @@ -292,11 +290,9 @@ export class Link extends Component { (type && size ? (' btn-' + size) : ''); var isNewWindow = this._isNewWindow(url); var doStripDomain = this._doStripDomain(); - if ( - url.indexOf('@') >= 0 && url.indexOf('mailto:') < 0 && !url.match(/^http[s]?/i) || - this._link && this._link.href.includes('mailto:') && !url.includes('mailto:') - ) { - url = ('mailto:' + url); + const emailMatch = url.match(EMAIL_REGEX); + if (emailMatch) { + url = emailMatch[1] ? emailMatch[0] : 'mailto:' + emailMatch[0]; } else if (url.indexOf(location.origin) === 0 && doStripDomain) { url = url.slice(location.origin.length); }