Splekke
Splekke

Reputation: 81

GMail converts link parameters to wrong format

I've made a function in java which sends a HTML e-mail with a link to the user.
It works perfectly in all e-mail clients except for GMail.
When clicked, GMail redirects the link via Google and reformats the link parameters like so:

Orignal Link
https://www.mylink.com/page.html?id=0&role=admin

To

Formatted Link
https://www.google.com/url?q=https://www.mylink.com/page.html?id%3D0%26role%3Dadmin

As you can see, the url parameters are in a weird format so I can't get these parameters out of the url with my javascript function.
Is there any way to prevent this?

Thanks for your help in advance.

Upvotes: 0

Views: 221

Answers (1)

Mark
Mark

Reputation: 5239

The url you're seeing is encoded, in Java you can get the unencoded URL with URLDecoder.decode:

String url = "https://www.google.com/url?q=https://www.mylink.com/page.html?id%3D0%26role%3Dadmin";
System.out.println(URLDecoder.decode(url, "UTF-8"));

This prints:

https://www.google.com/url?q=https://www.mylink.com/page.html?id=0&role=admin

Javascript also has the function to do this, it's called decodeURI().

Upvotes: 1

Related Questions