[FIX] mail: avoid double encodeURI

Before this PR, if a user copy/past an already encoded url in the composer, the
linkify function would reencode already encoded character.

`%5B%5D` (witch mean `[]`) would become `%255B%255D` because `%` whould be encoded
`%25`.

We start by decoding the url, just in case it's already encoded.

closes odoo/odoo#133010

X-original-commit: 453c91d9c5b0353b5f362ecad487ccfd547856c6
Signed-off-by: Matthieu Stockbauer (tsm) <tsm@odoo.com>
Signed-off-by: Didier Debondt (did) <did@odoo.com>
This commit is contained in:
Didier (did)
2023-08-24 20:59:04 +02:00
parent 139ff18221
commit b6f0e6ed65
2 changed files with 4 additions and 1 deletions
@@ -107,7 +107,8 @@ function linkify(text) {
let match;
while ((match = urlRegexp.exec(text)) !== null) {
result += _escapeEntities(text.slice(curIndex, match.index));
const url = match[0];
// Decode the url first, in case it's already an encoded url
const url = decodeURI(match[0]);
const href = encodeURI(!/^https?:\/\//i.test(url) ? "http://" + url : url);
result += `<a target="_blank" rel="noreferrer noopener" href="${href}">${_escapeEntities(
url
@@ -52,6 +52,8 @@ QUnit.test("addLink: utility function and special entities", function (assert) {
":'(": ":'(",
// special character in smileys should be escaped
"&lt;3": "&lt;3",
// Already encoded url should not be encoded twice
"https://odoo.com/%5B%5D": `<a target="_blank" rel="noreferrer noopener" href="https://odoo.com/%5B%5D">https://odoo.com/[]</a>`,
};
for (const [content, result] of Object.entries(testInputs)) {