Bug 15329 - luajson doesn't encode arrays with nil values properly
: luajson doesn't encode arrays with nil values properly
Status: CLOSED FIXED
Product: SqueezePlay
Classification: Unclassified
Component: SqueezeNetwork
: unspecified
: Other Other
: P1 critical (vote)
: 7.5.0
Assigned To: Andy Grundman
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-12-18 09:33 UTC by Andy Grundman
Modified: 2010-04-08 17:26 UTC (History)
5 users (show)

See Also:
Category: Bug


Attachments
Proposed patch (928 bytes, patch)
2009-12-21 14:46 UTC, Andy Grundman
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andy Grundman 2009-12-18 09:33:37 UTC
{ --[[table: 0x16e56050]]
  "a",
  "b",
  "c",
  nil,
  "d",
}

encodes to:

["a","b","c","d"]

but should be:

["a","b","c",null,"d"]
Comment 1 Michael Herger 2009-12-18 23:16:21 UTC
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
Comment 2 Andy Grundman 2009-12-21 14:46:09 UTC
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.
Comment 3 Richard Titmuss 2009-12-23 03:51:24 UTC
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.
Comment 4 Ben Klaas 2009-12-23 07:02:56 UTC
fwiw, if you decode that json it is not
["a","b","c",Json.null,"d"]
it's
["a","b","c","d"]
Comment 5 Andy Grundman 2009-12-23 07:03:58 UTC
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. :)
Comment 6 SVN Bot 2009-12-27 19:47:39 UTC
 == 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
Comment 7 Chris Owens 2010-04-08 17:26:11 UTC
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!