Escape string in manner compatible with JS

  1. I realize this is a terrible idea. I currently see no better alternative for XY problem.

  2. I have a Rust string. I need to escape it in a way compatible with JS. I can choose to put the string as 'foo' or "foo"; i.e. I have the choice of ' vs " for string character.

  3. Is escape in escape_string - Rust compatible with JS for either '' or "" ? If not, what is recommended to escaping the string in a way compatible with JS ?

Can't you just JSON-encode the string?


JSON used to have some slight differences in parsing strings, but this was resolved in es2019, which is universally implemented by everything that matters, and the problem was unlikely in the first place (who uses the LINE_SEPARATOR character?)

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.