Page 1 of 1

[0.18.28] Space breaks json parse

Posted: Sat May 30, 2020 4:33 pm
by Cooldude2606
Found a small bug with game.json_to_table.
Adding a space after a comma or near the brackets stops the parser. Note a space after a colon has no effect.
It would be nice if we could be allowed a space after the comma so it is more human readable.

Code: Select all

game.json_to_table('{"foo":[1,2,3],"bar":[1,2,3]}') -- returns { foo = { 1,2,3 }, bar = { 1,2,3 } }
game.json_to_table('{"foo": [1,2,3],"bar": [1,2,3]}') -- returns { foo = { 1,2,3 }, bar = { 1,2,3 } }
game.json_to_table('{"foo": [1,2,3], "bar": [1,2,3]}') -- returns nil
game.json_to_table('{ "foo": [1,2,3],"bar": [1,2,3] }') -- returns nil

Re: [0.18.28] Space breaks json parse

Posted: Tue Jun 02, 2020 4:43 pm
by posila
Thanks for the report. Unfortunatelly, when I copy&paste your examples into console in 0.18.28, all of them parse into table {bar = {1, 2, 3}, foo = {1, 2, 3}}

commands that I ran:

Code: Select all

/c game.print(serpent.line( game.json_to_table('{"foo": [1,2,3], "bar": [1,2,3]}') ))
/c game.print(serpent.line( game.json_to_table('{ "foo": [1,2,3],"bar": [1,2,3] }') ))

Re: [0.18.28] Space breaks json parse

Posted: Tue Jun 02, 2020 8:56 pm
by Cooldude2606
Sorry for the report, I have looked further into it and it appears that my custom command handler has an issue with parsing commands which include lots of quotation marks.
This results in my commands becoming the following after parse:

Code: Select all

game.print(serpent.line( game.json_to_table('{"foo": [1,2,3],_"bar": [1,2,3]}') ))
This will of course lead to json parse breaking. You can move this to not a bug as this is an issue with my custom code.