From 16b70f8c68c8afa5e46cee4bba9cb486d77f98c0 Mon Sep 17 00:00:00 2001 From: "Julien (jula)" <jula@odoo.com> Date: Tue, 25 Jul 2023 12:22:34 +0000 Subject: [PATCH] [FIX] mail: fixes linkify for url with subdomain __Current behavior before this commit:__ URLs that have a subdomain different than `www` and a domain name with more than 13 characters are not properly linkified in the chatter. __Description of the fix:__ The url regexp was changed with [0dc68dc](https://github.com/odoo/odoo/commit/0dc68dcc94ab9bb2e47943967fa2bc31780d20fa) to make punctuation mark the end of url to linkify. The 1st dot removed in diff was a mistake. This commit reverts this part, so that url above is correctly linkified while fixing the problem. Back-Port-Of: [#124974](https://github.com/odoo/odoo/pull/124974) opw-3423997 closes odoo/odoo#129565 Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com> --- addons/mail/static/src/js/utils.js | 2 +- .../tests/qunit_suite_tests/utils/mail_utils_tests.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/mail/static/src/js/utils.js b/addons/mail/static/src/js/utils.js index b93b115ebe91..164c3765264f 100644 --- a/addons/mail/static/src/js/utils.js +++ b/addons/mail/static/src/js/utils.js @@ -65,7 +65,7 @@ var _escapeEntities = (function () { // Suggested URL Javascript regex of http://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url // Adapted to make http(s):// not required if (and only if) www. is given. So `should.notmatch` does not match. // And further extended to include Latin-1 Supplement, Latin Extended-A, Latin Extended-B and Latin Extended Additional. -var urlRegexp = /\b(?:https?:\/\/\d{1,3}(?:\.\d{1,3}){3}|(?:https?:\/\/|(?:www\.))[-a-z0-9@:%_+~#=\u00C0-\u024F\u1E00-\u1EFF]{2,256}\.[a-z]{2,13})\b(?:[-a-z0-9@:%_+~#?&[\]^|{}`\\'$//=\u00C0-\u024F\u1E00-\u1EFF]|,(?!$| )|\.(?!$| |\.)|;(?!$| ))*/gi; +var urlRegexp = /\b(?:https?:\/\/\d{1,3}(?:\.\d{1,3}){3}|(?:https?:\/\/|(?:www\.))[-a-z0-9@:%._+~#=\u00C0-\u024F\u1E00-\u1EFF]{2,256}\.[a-z]{2,13})\b(?:[-a-z0-9@:%_+~#?&[\]^|{}`\\'$//=\u00C0-\u024F\u1E00-\u1EFF]|,(?!$| )|\.(?!$| |\.)|;(?!$| ))*/gi; /** * @param {string} text * @param {Object} [attrs={}] diff --git a/addons/mail/static/tests/qunit_suite_tests/utils/mail_utils_tests.js b/addons/mail/static/tests/qunit_suite_tests/utils/mail_utils_tests.js index 11a63975ede9..9d1f439605e4 100644 --- a/addons/mail/static/tests/qunit_suite_tests/utils/mail_utils_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/utils/mail_utils_tests.js @@ -8,7 +8,7 @@ QUnit.module('mail', {}, function () { QUnit.module('Mail utils'); QUnit.test('add_link utility function', function (assert) { - assert.expect(19); + assert.expect(27); var testInputs = { 'http://admin:password@example.com:8/%2020': true, @@ -22,6 +22,14 @@ QUnit.test('add_link utility function', function (assert) { 'https://www.transifex.com/odoo/odoo-11/translate/#fr/$/119303430?q=text%3ATartiflette': true, 'https://tenor.com/view/chỗgiặt-dog-smile-gif-13860250': true, 'http://www.boîtenoire.be': true, + // Subdomain different than `www` with long domain name + 'https://xyz.veryveryveryveryverylongdomainname.com/example': true, + // Two subdomains + 'https://abc.xyz.veryveryveryveryverylongdomainname.com/example': true, + // Long domain name with www + 'https://www.veryveryveryveryverylongdomainname.com/example': true, + // Subdomain with numbers + 'https://www.45017478-master-all.runbot134.odoo.com/web': true, }; _.each(testInputs, function (willLinkify, content) { -- GitLab