fix(json): preserve empty arrays across decode + re-encode#1
Open
AlinsRan wants to merge 1 commit into
Open
Conversation
The shared cjson instance decoded JSON without the array metatable, so an
empty array (`[]`) lost its array identity across a decode + re-encode
cycle and was re-encoded as an object (`{}`). This regressed OIDC userinfo
claims with empty arrays (e.g. `groups`, `roles`), silently turning them
into objects and breaking downstream systems expecting arrays.
Enable `decode_array_with_array_mt(true)` on the cjson instance at creation
so decoded arrays keep their metatable and round-trip as `[]`.
Synced from bungle#207.
📝 WalkthroughWalkthroughThe shared cjson.safe instance in encode_json and decode_json is configured with decode_array_with_array_mt(true) during lazy initialization, ensuring empty arrays are preserved as JSON arrays rather than converted to objects during encode/decode round-trips. A corresponding test case was added. ChangesEmpty Array Preservation
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The shared cjson instance in
utils.luadecoded JSON without the array metatable, so an empty array ([]) lost its array identity across a decode + re-encode cycle and was re-encoded as an object ({}):This regressed OIDC userinfo claims with empty arrays (e.g.
groups,roles), silently turning them into objects and breaking downstream systems that expect arrays.Fix
Enable
decode_array_with_array_mt(true)on the cjson instance at creation so decoded arrays keep their metatable and round-trip as[]. Encode and decode share the instance, so the option is set wherever it is created first.Adds a regression test in
spec/01-utils_spec.lua.Upstream: bungle#207
Summary by CodeRabbit
Bug Fixes
[]after a decode/encode round trip instead of changing to{}.Tests