Ansuman
Ansuman

Reputation: 1494

Issue in encoding percent value

I'm encoding a URL string with % value in it.

URL string - Nanoparticles with 70 % Photoluminescence

but it's getting converted to

Nanoparticles%20with%2070%E2%80%89%25%20Photoluminescence and clicking on this is resulting a 404 page.

Could you please let me know how to escape these % values from encoding??

Upvotes: 1

Views: 54

Answers (1)

JJJ
JJJ

Reputation: 33163

%E2%80%89 is Unicode character THIN SPACE, which means that the space between 70 and % is not a normal space (%20).

You'll either have to fix the space manually (just delete it and press spacebar), or if you can't do that, you need to replace it with a normal space programmatically before encoding:

encodeURI( 'Nanoparticles with 70 % Photoluminescence'.replace( /\u2009/g, ' ' ) );

Upvotes: 3

Related Questions