Weird domain injection in mailto link

Ok. So, I’m trying to create an mailto link with a subject and a body. Obviously, it has to be encoded, but just one, slight little problem…

Unlike previous attempts with mailto and URL encoding, for some reason the domain is being injected into the $subject variable when included in the string.


<template obscure data-p1="hello" data-p2="">
    <a href="mailto:%1@%2?subject={{$subject}}">%1@%2</a>

is rendered by HUGO as this…

<a href=""></a>

Or some other screwed up variation.

It prints fine outside of the anchor tag, but not inside of it… I have no idea why it’s injecting the domain, but even removing it still doesn’t help.

I’ve tried manually encoding, replace and safeURL… still getting the weird injections and it never renders how it’s entered.

@jmooring, if you can help… always appreciated. There’s nothing to show for this unfortunately… I have to push the site out publicly, so I need a beautiful address, even if it’s missing some important parts. You can still head over to COVID-19 API | Bahamas and look at the code for what it’s worth… le sigh

Your subject contains spaces, which are encoded as %20.
Your script replaces %2 with the domain.

This is, obviously, a bit fragile depending on the which characters exist in the subject.

While still fragile, you could change your script and template to use the underscore character instead of a percent symbol.

Hey Joe (@jmooring), I didn’t expect you until Monday. Thought you would be taking in the weekend.

I will make an adjustment for the script, but is HUGO taking something from it because it seemed the source code was affected, too, and not just the render.

I’ll give it a whirl and then get back to you.

No. This is a JS problem. Test by taking Hugo out of the equation:

<a href="mailto:%1@%2?subject=Hello%20World">%1@%2</a>

Not really an answer to the OP question, but GitHub - martignoni/hugo-cloak-email: A Hugo theme component to cloak email adresses could be useful for such use case.

The js is fine, just made a modification. Will update the plugin accordingly for future accomodations.

That’s for the info, though.

Hey @jmooring, it was the plugin. Made the necessary adjustments and will update the repository.

We’re coming along nicely, btw…

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.