[FIX] web_editor: fix url regex on Safari iOS
Commit [1] introduced a stronger regex to detect urls. Unfortunately, it did so using a negative lookbehind, which is is only supported on very recent version of Safari iOS. This commit is an attempt at reproducing the same behavior, albeit with a more complicated regex, unfortunately. [1]: https://github.com/odoo/odoo/commit/a42a19e484d63cebeaed10b75ac20e507ff85d56 closes odoo/odoo#134943 X-original-commit: ff99e454e2a38ae54aa57cb0df80df139e921ccb Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
@@ -47,7 +47,7 @@ const tldWhitelist = [
|
||||
'ug', 'uk', 'um', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn',
|
||||
'vu', 'wf', 'ws', 'ye', 'yt', 'yu', 'za', 'zm', 'zr', 'zw', 'co\\.uk'];
|
||||
|
||||
const urlRegexBase = `|(?:[-a-zA-Z0-9@:%._\\+~#=]{1,64}\\.))[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-zA-Z][a-zA-Z0-9]{1,62}|(?:[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.(?:${tldWhitelist.join('|')})\\b))(?:(?:[/?#])[^\\s]*(?<![.,})\\]'"]))?`;
|
||||
const urlRegexBase = `|(?:[-a-zA-Z0-9@:%._\\+~#=]{1,64}\\.))[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-zA-Z][a-zA-Z0-9]{1,62}|(?:[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.(?:${tldWhitelist.join('|')})\\b))(?:\\/[^\\s.,'")}\\]]*[?#.,)}\\]'"]?[^\\s.,'")}\\]]+|(?:[^!(){}.,\\[\\]'"\\s]+)|\\/[^\\s.,'")}\\]]*[^\\s?#.,'")}\\]]*)?`;
|
||||
const httpRegex = `(?:https?:\\/\\/)`;
|
||||
const httpCapturedRegex= `(https?:\\/\\/)`;
|
||||
|
||||
|
||||
@@ -95,6 +95,16 @@ describe('Link', () => {
|
||||
testNotUrlRegex('a.b.bc');
|
||||
testNotUrlRegex('20.08.2022');
|
||||
testNotUrlRegex('31.12');
|
||||
|
||||
// Url data and anchors count as part of the url.
|
||||
testUrlRegex('google.com?data=hello', { expectedUrl: 'google.com?data=hello' });
|
||||
testUrlRegex('google.com/?data=hello', { expectedUrl: 'google.com/?data=hello' });
|
||||
testUrlRegex('google.com/foo/?data=hello', { expectedUrl: 'google.com/foo/?data=hello' });
|
||||
testUrlRegex('google.com/.?data=hello', { expectedUrl: 'google.com/.?data=hello' });
|
||||
testUrlRegex('google.com?data=hello#anchor', { expectedUrl: 'google.com?data=hello#anchor' });
|
||||
testUrlRegex('google.com/?data=hello#anchor', { expectedUrl: 'google.com/?data=hello#anchor' });
|
||||
testUrlRegex('google.com/.?data=hello#anchor', { expectedUrl: 'google.com/.?data=hello#anchor' });
|
||||
testUrlRegex('google.com/foo/?data=hello&data2=foo#anchor', { expectedUrl: 'google.com/foo/?data=hello&data2=foo#anchor' });
|
||||
});
|
||||
describe('insert Link', () => {
|
||||
// This fails, but why would the cursor stay inside the link
|
||||
|
||||
Reference in New Issue
Block a user