These are chat archives for opal/opal

3rd
May 2018
Renato Marinho
@renatomarinho
May 03 2018 04:44
This message was deleted
eiko
@eiko
May 03 2018 15:32
@catmando which characters are not properly escaped?
Mitch VanDuyn
@catmando
May 03 2018 15:42
@eiko not sure at this point... we have had that patch in code for a while. Perhaps @adamcreekroad can remember... I will ping him.
so I think it was something like carriage return followed by pound sign. But I guess the question is why not just use js to do the the conversion???
Adam
@adamcreekroad
May 03 2018 15:57
Alright here is a very basic case:
foo = "#{"

foo.$to_json()
=> ""\#{""

JSON.parse(foo.$to_json())
=> Uncaught SyntaxError: Unexpected token # in JSON at position 2
       at JSON.parse (<anonymous>)
       at <anonymous>:1:6


JSON.stringify(foo)
# => ""#{""

JSON.parse(JSON.stringify(foo))
# =>"#{"
Elia Schito
@elia
May 03 2018 15:58
@catmando go for it
Mitch VanDuyn
@catmando
May 03 2018 15:59
just wondering why this isn't the way it is working already (i.e. just use JSON.stringify) perhaps there was a good reason I don't want to miss?
Elia Schito
@elia
May 03 2018 16:01
@catmando it's super old stuff, 4yrs+ ago, I don't think there was a particular reason
Mitch VanDuyn
@catmando
May 03 2018 16:01
okay... well we will get a PR in then
eiko
@eiko
May 03 2018 16:21
looks like right now, string.to_json just aliases to string.inspect. the bug happens because inspect escapes #{ to avoid confusion with ruby's string interpolation.
Mitch VanDuyn
@catmando
May 03 2018 16:24
so that makes sense... somebody just figured, hey use inspect. But in reality using JSON.stringify should be the right answer yes?
eiko
@eiko
May 03 2018 16:53
yes, i think so!
Elia Schito
@elia
May 03 2018 22:41
@catmando remember to che that stringify with a string works on most browsers