diff options
| author | Didier (did) <did@odoo.com> | 2021-04-01 10:47:47 +0000 |
|---|---|---|
| committer | Sébastien Theys <seb@odoo.com> | 2021-04-01 17:50:46 +0000 |
| commit | d825f88d96f2cc7abffe2c2d750891966cfcdd43 (patch) | |
| tree | 9e067f80f816646e1b19cc1217f5ba9b72d41234 /addons/mail | |
| parent | 26976764554af3016097f1659b563e75757148e3 (diff) | |
[FIX] mail: detect a bigger range of URL in messages
Current URL regexp doesn't support special, but still valid, character like `é`,
`è`, `ỗ`, `ặ`, etc.
Url like `https://tenor.com/view/chỗgiặt-dog-smile-gif-13860250` are not going
to be matched correctly.
This commit adds the support for Latin-1 Supplement, Latin Extended-A,
Latin Extended-B and Latin Extended Additional unicode.
Some relevant stackoverflow discussion:
https://stackoverflow.com/questions/20690499/concrete-javascript-regex-for-accented-characters-diacritics
task-2088895
closes odoo/odoo#68667
X-original-commit: 1f9c171115d8bbd81d382e353f3faadab16aedfc
Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
Diffstat (limited to 'addons/mail')
| -rw-r--r-- | addons/mail/static/src/js/utils.js | 3 | ||||
| -rw-r--r-- | addons/mail/static/tests/mail_utils_tests.js | 4 |
2 files changed, 5 insertions, 2 deletions
diff --git a/addons/mail/static/src/js/utils.js b/addons/mail/static/src/js/utils.js index c65b4b339b3..d267623de2c 100644 --- a/addons/mail/static/src/js/utils.js +++ b/addons/mail/static/src/js/utils.js @@ -45,7 +45,8 @@ function _parseAndTransform(nodes, transformFunction) { // 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. -var urlRegexp = /\b(?:https?:\/\/\d{1,3}(?:\.\d{1,3}){3}|(?:https?:\/\/|(?:www\.))[-a-z0-9@:%._+~#=]{2,256}\.[a-z]{2,13})\b(?:[-a-z0-9@:%_+.~#?&'$//=;]*)/gi; +// 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; /** * @param {string} text * @param {Object} [attrs={}] diff --git a/addons/mail/static/tests/mail_utils_tests.js b/addons/mail/static/tests/mail_utils_tests.js index 6d5d7c7415d..b330dc377ba 100644 --- a/addons/mail/static/tests/mail_utils_tests.js +++ b/addons/mail/static/tests/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(15); + assert.expect(19); var testInputs = { 'http://admin:password@example.com:8/%2020': true, @@ -20,6 +20,8 @@ QUnit.test('add_link utility function', function (assert) { 'fhttps://test.example.com/test': false, "https://www.transifex.com/odoo/odoo-11/translate/#fr/lunch?q=text%3A'La+Tartiflette'": true, '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, }; _.each(testInputs, function (willLinkify, content) { |
