Alternatives to encodeURI and encodeURIComponent to replace escape
Asked Answered
S

0

0

I am posting data to a site that often includes French characters. This site has a form which handles the French characters fine but I had trouble when sending doing this inside a node program.

An example would be a field with the name: "Maevà". When I look at the dev tools in chrome I can see that the request encodes this name as: Maev%E0.

This works fine and in my code if I use escape(Maevà) it returns Maev%E0 which works perfectly.

Unfortunately escape is deprecated so I tried to use encodeURIComponent and encodeURI but they both return Maev%C3%A0 which does not work.

Is there something else I can use?

Supremacist answered 24/4, 2023 at 14:22 Comment(3)
Maev%C3%A0 is the correct encoding. You can see it correctly populating the input when used in a Google Search URL - google.com/search?q=-----Maev%C3%A0----- (it sounds like you have a problem with whatever code you have to decode that data and you should be looking to fix that instead of trying to reproduce the behaviour of escape)Carranza
Chrome seems to encode it the same way though so surely it's just an alternative encoding that I should be able to replicate without escape?Supremacist
"This site has a form which handles the French characters fine" - please show us that form, and ideally post the server code that handles the request.Coulter

© 2022 - 2024 — McMap. All rights reserved.