stdweb icon indicating copy to clipboard operation
stdweb copied to clipboard

Unicode Escape Sequences in Strings in js! Macro

Open WalkerCodeRanger opened this issue 6 years ago • 0 comments

Unicode escape sequences in strings are not handled correctly in the js! macro.

A valid JavaScript string like "Proof that this isn't JS\u0021" will given an error that:

error: incorrect unicode escape sequence
 --> src\main.rs:8:34
  |
8 |         alert("Proof that this isn't JS\u0021");
  |                                        ^^----
  |                                        |
  |                                        help: format of unicode escape sequences uses braces: `\u{0021}`

Trying to use a Rust escape sequence like "Proof that this isn't JS\u{0021}" prints lots to the console and then says:

ValueError: Invalid \uXXXX escape: line 16 column 771 (char 66953)

However, this works "Proof that this isn't JS\\u{0021}" (note the double backslash). This is certainly not valid JavaScript and doesn't even make sense for Rust.

WalkerCodeRanger avatar Jun 14 '19 01:06 WalkerCodeRanger