JSON parser tolerates illegal commas
- Dominant language
- Rust
- Stars
- 3.6k
- Forks
- 1.3k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 169
Description
**Describe the bug**
The JSON tape decoder currently accepts invalid JSON such as:
```json
{, "a": 1, ,,, , "b":2,, }
[,, 1, ,,, , 2, ]
```
**To Reproduce**
Try parsing the above JSON.
**Expected behavior**
Leading, trailing, and repeated commas should produce a parsing error.
From the [JSON spec](https://www.json.org/json-en.html):
> An object is an unordered set of name/value pairs. An object begins with `{` left brace and ends with `}` right brace. Each name is followed by `:` colon and the name/value pairs are separated by `,` comma.
>
> An array is an ordered collection of values. An array begins with `[` left bracket and ends with `]` right bracket. Values are separated by `,` comma.
>
**Additional context**
The tape decoder lacks a `DecoderState::Comma` enum variant. Instead `DecoderState::Object` and `DecoderState::List` both rely on the following (overly permissive) string search:
```rust
iter.advance_until(|b| !json_whitespace(b) && b != b',');
```
Contributor guide
Research direction
The tape decoder's DecoderState::Object and DecoderState::List handling is the entry point; inspect their comma-skipping logic first. Add coverage for leading, trailing, and repeated commas in the JSON examples and verify each now produces a parsing error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100