[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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user