Skip to content
Snippets Groups Projects
Commit a6978bcb authored by Rodolpho Lima's avatar Rodolpho Lima
Browse files

[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

Part-of: odoo/odoo#118676
parent 99716f4d
Branches
Tags
No related merge requests found
......@@ -289,12 +289,10 @@ const Link = Widget.extend({
* @private
*/
_correctLink: function (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;
......@@ -341,11 +339,9 @@ const Link = Widget.extend({
(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);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment