[FIX] website: fix email sharing subject format
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) <sobo@odoo.com>
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user