0
I'm adding a custom link to a SendGrid template.
Part of the link is some url query parameters. They're separated by an ampersand (&), like so:
<a href="www.example.com?arg1=foo&arg2=bar">My Link</a>
Sendgrid keeps auto-updating the string above, escaping the character and creating this:
<a href="www.example.com?arg1=foo&arg2=bar">My Link</a>
This is not the same link at all, and I would like it to not force character escaping in my custom html code.
And no, these two links are not the same
const t1 = new URLSearchParams("a=1&b=2");
console.log(t1.get("a")); // 1
console.log(t1.get("b")); // null
console.log(t1.get("amp;b")); // 2
const t2 = new URLSearchParams("a=1&b=2");
console.log(t2.get("a")); // 1
console.log(t2.get("b")); // 2
How can I make SendGrid allow me to use a ampersand?
Does it end up in the raw generated email as
&
,&
, or&amp;
? – user1686 – 2019-05-15T19:36:32.310&
. Exactly as shown above – Seph Reed – 2019-05-15T19:44:12.5301Then there is no problem. That is what an HTML file is supposed to have. – user1686 – 2019-05-15T19:49:36.537
I'm working with a url, not an html file. Escaping characters is something you do for text in an html file, and certain characters in url sometimes. This is not one of those cases, I'd like the characters to not be escaped. See my edit for details on why having
&
does not work. – Seph Reed – 2019-05-15T20:25:36.377Might not be an issue but are your actual links like
<a href="www…
? Where is the HTTP or HTTPS? Should it not be<a href="http://www…
or<a href="https://www…
? – JakeGould – 2019-05-15T20:38:05.960@Seph: If it has
<a href
around it, it is HTML. Your JS console example doesn't seem relevant, because it does not go through the HTML parser which is what the entity ref is for. – user1686 – 2019-05-15T20:40:15.983The page loads just fine, it's just the search params which are flawed.
@grawity Check out this link https://www.google.com/?a=hat&q=test. Then try relpacing
&
with&
.You keep missing the point... the
&
is not part of the URL, it's part of the HTML. Just like the HTML generator converts&
to&
, the HTML parser converts it back to a lone&
when showing the link. If you deliberately add it to the raw URL, bypassing the HTML parser, of course it won't work because that's not what it's for. – user1686 – 2019-05-16T15:15:55.607If it was acting as just html, yes (https://jsfiddle.net/d6Lb9an3/). But I=it ends up becoming part of the url though. I'm not lying about this. If I click the link, the url has
&
in it, and is a broken link.In any case, I've switched over to Postmark, so it's not really something I need anymore, but without the ability to add a non-exited ampersand, my links were broken.