Phrogz / NeatJSON

Pretty-print your JSON in Ruby, JS, or Lua with more power than JSON.stringify or JSON.pretty_generate
http://phrogz.net/JS/NeatJSON
MIT License
108 stars 19 forks source link

Lua version has improper character escaping #34

Open Phrogz opened 1 year ago

Phrogz commented 1 year ago
~/code/NeatJSON/test$ lua test_neatjson.lua 
neatJSON("foo\9bar")
EXPECTED
"foo\tbar"
ACTUAL
"foo\9bar"

neatJSON("foo\13bar")
EXPECTED
"foo\rbar"
ACTUAL
"foo\13bar"

neatJSON("foo\8bar")
EXPECTED
"foo\bbar"
ACTUAL
"foo\8bar"

neatJSON("foo\12bar")
EXPECTED
"foo\fbar"
ACTUAL
"foo\12bar"

This is valid Lua escaping, but not valid JSON escaping. At a minimum need to convert \9 to \u0009 to be valid JSON; would be preferable to use the nicer escapes for \n \t \r \f.