decodeURI not replacing & with &

Viewed 21

I'm using decodeURI on a Vue project I'm working on. Though, the API I'm utilising (Reddit) it returning encoded URL's for their images. decodeURI is working to an extent, but it is not replacing & with the correct &.

Is there a way to fix this?

<img :src="decodeURI(post.data.preview.images[0].source.url)" :alt=post.data.title />
1 Answers

The decodeURI() function decodes what encodeURI() encodes.

Since & will not be encoded by encodeURI(), decodeURI() won't decode &amp;.

console.log(encodeURI("&"));

Related