fix(core/json): stably_encode fails to encode cjson.null values#13281
Open
rickyxucn wants to merge 1 commit intoapache:masterfrom
Open
fix(core/json): stably_encode fails to encode cjson.null values#13281rickyxucn wants to merge 1 commit intoapache:masterfrom
rickyxucn wants to merge 1 commit intoapache:masterfrom
Conversation
The stably_encode function used dkjson.encode directly, which does not recognize cjson.null (a userdata) and fails to encode it properly. This fix adds a convert_cjson_null helper that recursively converts cjson.null to dkjson.null before encoding. This ensures tables containing cjson.null values can be stably encoded as valid JSON with null literals. Also added 4 test cases in t/core/json.t to cover: - simple table with cjson.null - nested table with cjson.null - encoding stability with cjson.null - top-level cjson.null encoding Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1ecd73b to
2dbb890
Compare
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.
The stably_encode function used dkjson.encode directly, which does not recognize cjson.null (a userdata) and fails to encode it properly.
This fix adds a convert_cjson_null helper that recursively converts cjson.null to dkjson.null before encoding. This ensures tables containing cjson.null values can be stably encoded as valid JSON with null literals.
Also added 4 test cases in t/core/json.t to cover:
Description
Which issue(s) this PR fixes:
Fixes #
Checklist