Report the comma position for illegal trailing comma errors - #382
Merged
Conversation
Both scanners reported the position of the closing bracket, or in the pure-Python array case whatever character happened to precede it, rather than the offending comma. The comma index is captured right after the delimiter is confirmed, so it survives the whitespace skip that follows. This is what CPython's json.decoder does with its own comma_idx, and it makes all four sites (object and array, C and pure-Python) report the same position as the stdlib.
etrepum
approved these changes
Aug 26, 2026
netbsd-srcmastr
pushed a commit
to NetBSD/pkgsrc
that referenced
this pull request
Aug 28, 2026
Version 4.1.2 released 2026-08-26 * Fix control character error position when content precedes the control char simplejson/simplejson#379 * Report the offending char, not the backslash, for invalid \X escapes simplejson/simplejson#380 * Handle non-finite Decimals like floats in the encoder simplejson/simplejson#381 * Parse failures due to trailing commas are now reported consistently across implementations simplejson/simplejson#382
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.
Differential fuzzing of the C scanner against the pure-Python fallback (
_toggle_speedups) found 61 divergences in 12,000 random decode inputs, all of them the position reported for an illegal trailing comma in an array:Cause
ERR_TRAILING_COMMA_*is raised after the whitespace following the comma has been skipped, so the index passed no longer refers to it. The C scanner passesidx, the closing bracket.JSONArraypassesend - 1, an idiom copied from the delimiter error a few lines up whereendhad been incremented; here it has not, so the reported character is whatever precedes].Fix
Capture the comma index when the delimiter is confirmed and report that, as
json/decoder.pydoes with its owncomma_idx. Four sites:JSONObject,JSONArray, and the object and array branches of the scan template. Trailing-comma detection landed in 4.0.0 as CPython parity (#371), so stdlib breaks the tie.Result
Same corpus: 61 divergences before, 0 after. Refiltering it to drop trailing commas gives 0 both before and after. Encode was fuzzed alongside and showed 0.
test_trailing_comma_positionpins the offsets for both containers, whitespace after the comma, and nesting, and_cibw_runnerruns it on both paths. Reverting onlydecoder.pyfails it on the Python path, only_speedups_scan.hon the C path. Suite passes on both (460 tests, was 458). The C change builds clean under the-Werrorflags in AGENTS.md. I could not exercise the Py2_strinstantiation locally.