Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luci-lib-jsonc: fix handling of strange keys, allow encoding [] #457

Merged
merged 2 commits into from
Aug 30, 2015
Merged

luci-lib-jsonc: fix handling of strange keys, allow encoding [] #457

merged 2 commits into from
Aug 30, 2015

Conversation

jplitza
Copy link
Contributor

@jplitza jplitza commented Aug 30, 2015

No description provided.

Previously, the following caused a segmentation fault:

    json.stringify({[{}] = true})

This was caused by lua_tostring() returning NULL for anything but
strings and numbers, letting json_object_object_add crash.

This patch makes jsonc ignore all keys which have no string
representation altogether.

Signed-off-by: Jan-Philipp Litza <[email protected]>
To be consistent with the behavior of luci-lib-json, an empty Lua table
should be encoded to an empty JSON list, not an empty JSON object.

To still allow encoding empty JSON objects, the usage of anything other
than a number or a string as a key (for example an empty table or a
function) can be used to force encoding as an object:

    json.stringify({})                  -- "[]"
    json.stringify({[{}] = true})       -- "{}"

Signed-off-by: Jan-Philipp Litza <[email protected]>
jow- added a commit that referenced this pull request Aug 30, 2015
luci-lib-jsonc: fix handling of strange keys, allow encoding []
@jow- jow- merged commit a36a73c into openwrt:master Aug 30, 2015
@jow-
Copy link
Contributor

jow- commented Aug 30, 2015

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants