timo / json_fast

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

to-json incorrect encoding of new-line combiners #19

Closed dwarring closed 7 years ago

dwarring commented 7 years ago

Consider

use JSON::Fast;
use Test;

is to-json("ab\rc"), '"ab\rc"';
is to-json("ab\nc"), '"ab\nc"';
is to-json("ab\r\nc"), '"ab\r\nc"';
lives-ok { from-json(to-json("ab\r\nc")) };

done-testing;

Produces:

$ perl6 /tmp/json-enc.t
ok 1 - 
ok 2 - 
not ok 3 - 

# Failed test at /tmp/tst.pl line 6
# expected: '"ab\r\nc"'
#      got: '"ab
c"'
not ok 4 - 

# Failed test at /tmp/tst.pl line 7
# at 4: the only whitespace allowed in json strings are spaces
1..4
# Looks like you failed 2 tests of 4

The "\r\n" sequence does not seem to encode correctly.

timo commented 7 years ago

wtf, i didn't even see this issue and ended up hunting it for like half a whole day when you already did all the work. oh well! thanks for trying to contribute, i'll check my issue queue more regularly in the future!

dwarring commented 7 years ago

No prob. Now all working, thanks