timo / json_fast

a naive imperative json parser in perl6, to evaluate performance against JSON::Tiny
Artistic License 2.0
27 stars 20 forks source link

to-json routine is no longer escaping double quotes in hash keys #70

Closed thundergnat closed 4 years ago

thundergnat commented 4 years ago

A very annoying bug popped up in the latest version. The to-json routine in no longer properly escaping double quote in hash key strings. It's probably not a common thing, but it happens. I have moderately large JSON files files I process every sunday and they failed hard after I had upgraded to 2020.07 and updated all my installed modules.

use JSON::Fast;
my %data = 'It\'s the "REAL" deal!' => 'BORKEN!!';
say my $json = %data.&to-json;
say "WAT!? The double quotes aren't escaped... that isn't valid JSON";
say $json.&from-json

Output

{
  "It's the "REAL" deal!": "BORKEN!!"
}
WAT!? The double quotes aren't escaped... that isn't valid JSON
unexpected R in an object at 15
  in block  at /home/steve/.perl6/share/perl6/site/sources/0FE3EE5CA05AEDC84BC326E7EBBACCB6647BD427 (JSON::Fast) line 594
  in sub parse-obj at /home/steve/.perl6/share/perl6/site/sources/0FE3EE5CA05AEDC84BC326E7EBBACCB6647BD427 (JSON::Fast) line 556
  in sub parse-thing at /home/steve/.perl6/share/perl6/site/sources/0FE3EE5CA05AEDC84BC326E7EBBACCB6647BD427 (JSON::Fast) line 647
  in sub from-json at /home/steve/.perl6/share/perl6/site/sources/0FE3EE5CA05AEDC84BC326E7EBBACCB6647BD427 (JSON::Fast) line 683
  in block <unit> at myjson.p6 line 9

Seems to only be an issue in hash keys, regular strings are ok

timo commented 4 years ago

fixed in release 0.14