From 9e9b9aa941b060dd651bc6bf53e7d8fdc1283cce Mon Sep 17 00:00:00 2001 From: "Robin Lejeune (role)" Date: Tue, 21 Nov 2023 13:08:53 +0100 Subject: [PATCH] [FIX] website: fix email sharing subject format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce: - Drop a "Share" snippet anywhere on the page and save. - Click on the email icon. - Your default email client should open with, as a subject line, the title of the page where spaces are replaced by +. => This should not be the case, spaces should show as spaces. Since the sharer refactoring in [1], the title of a page used in share buttons of the `s_share` snippet is encoded as a `URLSearchParams()`, which encodes spaces as "+" characters (see the specs [2] of the built-in method). This works fine for most share buttons, but not for email clients, which do not properly parse the "+". Typically, that means that the subject line of the mailto link is something like "Home+%7C+My+Website", which renders as "Home+|+My+Website" in a mail client, instead of showing spaces. This commit uses another way to encode the title parameter, so that it works for every share button. It also replaces a space that was encoded twice for Whatsapp. [1]: https://github.com/odoo/odoo/commit/5297388cd2aa1f693b04538c846c7025e243b09d [2]: https://url.spec.whatwg.org/#ref-for-urlsearchparams%E2%91%A4 task-3603556 closes odoo/odoo#142876 Signed-off-by: Soukéina Bojabza (sobo) --- addons/website/static/src/snippets/s_share/000.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/addons/website/static/src/snippets/s_share/000.js b/addons/website/static/src/snippets/s_share/000.js index ce2742c73e2..14637d83b40 100644 --- a/addons/website/static/src/snippets/s_share/000.js +++ b/addons/website/static/src/snippets/s_share/000.js @@ -59,9 +59,13 @@ const ShareWidget = publicWidget.Widget.extend({ // parameter, merging everything together, e.g of output: // https://wa.me/?text=%20OpenWood%20Collection%20Online%20Reveal%20%7C%20My%20Website%20http%3A%2F%2Flocalhost%3A8888%2Fevent%2Fopenwood-collection-online-reveal-2021-06-21-2021-06-23-8%2Fregister // For more details, see https://faq.whatsapp.com/general/chats/how-to-use-click-to-chat/ - modifiedUrl.searchParams.set(titleParamFound, `${currentTitle}%20${currentUrl}`); + modifiedUrl.searchParams.set(titleParamFound, `${currentTitle} ${currentUrl}`); } else { - modifiedUrl.searchParams.set(titleParamFound, currentTitle); + // The built-in `URLSearchParams.set()` method encodes spaces + // as "+" characters, which are not properly parsed as spaces + // by email clients, so we can't use it here. + modifiedUrl.search = modifiedUrl.search + .replace(encodeURIComponent("{title}"), encodeURIComponent(currentTitle)); } }