[FIX] web_editor: properly capture any form of url on paste

The regex that automatically detect link when pasting text or
when pressing space when editing was not good enough and
for instance did not capture fully an url like:
https://1234-abc.runbot007.odoo.com/web#id=3&menu_id=221

Task ID: 2602725

closes odoo/odoo#73972

X-original-commit: ebe74cb8017ebadbdb6b651e43c59a1d506ba8de
Signed-off-by: Antoine Guenet <Zinston@users.noreply.github.com>
This commit is contained in:
Nicolas Bayet
2021-07-19 14:15:19 +00:00
parent 9581b97c18
commit bc25b371ef
3 changed files with 47 additions and 2 deletions
@@ -25,9 +25,10 @@ export const CTGROUPS = {
BR: CTYPES.BR,
};
export const URL_REGEX = /((?:https?:\/\/)?(?:[a-z0-9-]{1,63}\.){1,2}[a-z]{2,15}(?:\/[^\s]*)?)/gi;
export const URL_REGEX =
/((?:(?:https?:\/\/)|(?:[-a-zA-Z0-9@:%._\+~#=]{1,64}\.))[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,63}\b(?:[^\s]*))/gi;
export const URL_REGEX_WITH_INFOS =
/((https?:\/\/)?([a-z0-9-]{1,63}\.){1,2}[a-z]{2,15}(\/[^\s]*)?(\s|$))/gi;
/((?:(https?:\/\/)|(?:[-a-zA-Z0-9@:%._\+~#=]{1,64}\.))[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,63}\b(?:[^\s]*))/gi;
export const YOUTUBE_URL_GET_VIDEO_ID =
/^(?:(?:https?:)?\/\/)?(?:(?:www|m)\.)?(?:youtube\.com|youtu\.be)(?:\/(?:[\w-]+\?v=|embed\/|v\/)?)([^\s?&#]+)(?:\S+)?$/i;
@@ -7,6 +7,7 @@ import './spec/fontSize.test.js';
import './spec/insertHTML.test.js';
import './spec/fontAwesome.test.js';
import './spec/autostep.test.js';
import './spec/urlRegex.test.js';
mocha.run(failures => {
if (failures) {
@@ -0,0 +1,43 @@
import { URL_REGEX } from '../../src/OdooEditor.js';
describe('urlRegex', () => {
it('should not match foo.com', () => {
const url = 'foo.com';
const text = `abc ${url} abc`;
const match = text.match(URL_REGEX);
chai.expect(match).to.be.equal(null);
});
it('should match abc.abc.abc', () => {
const url = 'abc.abc.abc';
const text = `abc ${url} abc`;
const match = text.match(URL_REGEX);
chai.expect(match[0]).to.be.equal(url);
});
it('should match http://abc.abc.abc', () => {
const url = 'http://abc.abc.abc';
const text = `abc ${url} abc`;
const match = text.match(URL_REGEX);
chai.expect(match[0]).to.be.equal(url);
});
it('should match https://abc.abc.abc', () => {
const url = 'https://abc.abc.abc';
const text = `abc ${url} abc`;
const match = text.match(URL_REGEX);
chai.expect(match[0]).to.be.equal(url);
});
it('should match 1234-abc.runbot007.odoo.com/web#id=3&menu_id=221', () => {
const url = '1234-abc.runbot007.odoo.com/web#id=3&menu_id=221';
const text = `abc ${url} abc`;
const match = text.match(URL_REGEX);
chai.expect(match[0]).to.be.equal(url);
});
it('should match https://1234-abc.runbot007.odoo.com/web#id=3&menu_id=221', () => {
const url = 'https://1234-abc.runbot007.odoo.com/web#id=3&menu_id=221';
const text = `abc ${url} abc`;
const match = text.match(URL_REGEX);
chai.expect(match[0]).to.be.equal(url);
});
});