Skip to content
Snippets Groups Projects
Commit 9302a237 authored by tsm-odoo's avatar tsm-odoo
Browse files

[FIX] mail: incomplete url regex

The discuss app uses an url regex in order to find links and
transform them to html before posting a message.

Before this commit, some unsafe url characters  were missing
from this regex, resulting in incorrectly parsed url.

This commit adds missing characters in order to match RFC1738
[1].

[1]: https://www.ietf.org/rfc/rfc1738.txt



closes odoo/odoo#122093

Signed-off-by: default avatarAlexandre Kühn (aku) <aku@odoo.com>
parent 2f0928c8
No related branches found
No related tags found
No related merge requests found
......@@ -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={}]
......
/** @odoo-module **/
import * as utils from '@mail/js/utils';
import { start, startServer } from "@mail/../tests/helpers/test_utils";
QUnit.module('mail', {}, function () {
......@@ -137,4 +138,20 @@ QUnit.test('addLink: linkify inside text node (2 occurrences)', function (assert
);
});
QUnit.test("url", async (assert) => {
const pyEnv = await startServer();
const channelId = pyEnv["mail.channel"].create({ name: "General" });
const { click, insertText, openDiscuss } = await start({
discuss: {
context: { active_id: channelId },
},
});
await openDiscuss();
// see: https://www.ietf.org/rfc/rfc1738.txt
const messageBody = "https://odoo.com?test=~^|`{}[]#";
await insertText(".o_ComposerTextInput_textarea", messageBody);
await click("button:contains(Send)");
assert.containsOnce($, `.o_Message a:contains(${messageBody})`);
})
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment