0

We are interpolating a URL onto our page, it is coming from Rails and gets automatically escaped like so:

"http://foo.bar/path?key=val&key2=val2"

Notice & is there where it should be &.

This URL no longer works properly.

We did get it working by using Rails' raw method which prevents the escaping.

But I would prefer to do this using Javascript, and I'm sure there's a way.


I tried unescape, decodeURI, and decodeURIComponent, they don't work

str = "http://foo.bar/path?key=val&key2=val2"
decodeURIComponent(str) == str // true
decodeURI(str) == str // true
unescape(str) == str // true
max pleaner
  • 26,189
  • 9
  • 66
  • 118
  • 2
    Does this answer your question? [What is the difference between decodeURIComponent and decodeURI?](https://stackoverflow.com/questions/747641/what-is-the-difference-between-decodeuricomponent-and-decodeuri) – imvain2 May 20 '20 at 19:43
  • Just for your own reference, these encoded chars are called [**HTML Entities**](https://developer.mozilla.org/en-US/docs/Glossary/Entity). – gyohza May 20 '20 at 19:48
  • @imvain2 neither of those work with `&` – max pleaner May 20 '20 at 20:05

0 Answers0