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