[0.18.28] Space breaks json parse

Bugs that are actually features.
User avatar
Cooldude2606
Fast Inserter
Fast Inserter
Posts: 112
Joined: Sat Sep 16, 2017 9:04 pm
Contact:

[0.18.28] Space breaks json parse

Post 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
--- Developer for Explosive Gaming and Clusterio. Please contact me via our Discord. ---
posila
Former Staff
Former Staff
Posts: 5448
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: [0.18.28] Space breaks json parse

Post 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] }') ))
User avatar
Cooldude2606
Fast Inserter
Fast Inserter
Posts: 112
Joined: Sat Sep 16, 2017 9:04 pm
Contact:

Re: [0.18.28] Space breaks json parse

Post 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.
--- Developer for Explosive Gaming and Clusterio. Please contact me via our Discord. ---
Post Reply

Return to “Not a bug”