Bugzilla – Bug 15329
luajson doesn't encode arrays with nil values properly
Last modified: 2010-04-08 17:26:11 UTC
{ --[[table: 0x16e56050]] "a", "b", "c", nil, "d", } encodes to: ["a","b","c","d"] but should be: ["a","b","c",null,"d"]
from jived.log on production: [Fri Dec 18 22:09:38 2009] bad data in player_register: [ "", ["playerRegister", "00:04:20:26:9b:83", "Squeezebox Radio"], ] -> uuid missing
Created attachment 6399 [details] Proposed patch Richard can you review this patch? For some reason I can't work out, nil values in arrays seem to be skipped during the lua_next iterator. I hacked in a check that we get array indices that always increase by 1, if we skip any, we add a null to the JSON output. This still has a bug if the last array element is nil it's ignored, but we can live with that one for now.
This is really an application error, as 'nil' should be encoded Json.nil. I think if you decode that json it would be ["a","b","c",Json.null,"d"]. That said the fix looks good to catch places where nil is used in an array.
fwiw, if you decode that json it is not ["a","b","c",Json.null,"d"] it's ["a","b","c","d"]
Decoding doesn't seem to be an issue, the bug is only with encoding. I noticed there were a bunch of tests for decoding but none for encoding. :)
== Auto-comment from SVN commit #8268 to the jive repo by andy == == https://svn.slimdevices.com/jive?view=revision&revision=8268 == Fixed bug 15329, patch to encode JSON arrays with nil values correctly
This bug has been marked fixed in a released version of Squeezebox Server or the accompanying firmware or mysqueezebox.com release. If you are still seeing this issue, please let us know!