[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) <dmo@odoo.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -1473,15 +1473,15 @@ describe('Paste', () => {
|
||||
stepFunction: async editor => {
|
||||
await pasteText(editor, 'abc www.odoo.com xyz');
|
||||
},
|
||||
contentAfter: '<p>abc <a href="https://www.odoo.com">www.odoo.com</a> xyz[]</p>',
|
||||
contentAfter: '<p>abc <a href="http://www.odoo.com">www.odoo.com</a> xyz[]</p>',
|
||||
});
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: '<p><a href="#">[]\u200B</a></p>',
|
||||
stepFunction: async editor => {
|
||||
await pasteText(editor, 'odoo.com\ngoogle.com');
|
||||
},
|
||||
contentAfter: '<p style="margin-bottom: 0px;"><a href="https://odoo.com">odoo.com</a></p>' +
|
||||
'<p><a href="https://google.com">google.com</a>[]<br></p>'
|
||||
contentAfter: '<p style="margin-bottom: 0px;"><a href="http://odoo.com">odoo.com</a></p>' +
|
||||
'<p><a href="http://google.com">google.com</a>[]<br></p>'
|
||||
});
|
||||
});
|
||||
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: '<p><a href="https://www.odoo.com">www.odoo.com</a>[]</p>',
|
||||
contentAfter: '<p><a href="http://www.odoo.com">www.odoo.com</a>[]</p>',
|
||||
});
|
||||
await testEditor(BasicEditor, {
|
||||
contentBefore: '<p><a href="#">[xyz]</a></p>',
|
||||
stepFunction: async editor => {
|
||||
await pasteText(editor, 'abc www.odoo.com xyz');
|
||||
},
|
||||
contentAfter: '<p>abc <a href="https://www.odoo.com">www.odoo.com</a> xyz[]</p>',
|
||||
contentAfter: '<p>abc <a href="http://www.odoo.com">www.odoo.com</a> xyz[]</p>',
|
||||
});
|
||||
const imageUrl = 'https://download.odoocdn.com/icons/website/static/description/icon.png';
|
||||
await testEditor(BasicEditor, {
|
||||
|
||||
@@ -312,7 +312,7 @@ describe('Link', () => {
|
||||
stepFunction: async editor => {
|
||||
await deleteBackward(editor);
|
||||
},
|
||||
contentAfter: '<p>a<a href="https://hellomoto.com">hello[]moto.com</a></p>',
|
||||
contentAfter: '<p>a<a href="http://hellomoto.com">hello[]moto.com</a></p>',
|
||||
});
|
||||
});
|
||||
it('should change the url in one step', async () => {
|
||||
|
||||
Reference in New Issue
Block a user