From 524dc07d8ecc580b720522a5321ea5e6781c2f23 Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Fri, 8 Sep 2023 13:39:35 +0200 Subject: [PATCH] [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) --- .../src/js/editor/odoo-editor/src/utils/utils.js | 2 +- .../src/js/editor/odoo-editor/test/spec/link.test.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js index 0e4fdc5d2c5..79cf81436c0 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js @@ -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]*(? { 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