-
Notifications
You must be signed in to change notification settings - Fork 290
Check for trailing garbage inside json (rework #80) #149
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
Check for trailing garbage inside json (rework #80) #149
Conversation
e3a34e8
to
43b6a04
Compare
I have squashed the first commits from #80:
and left out the last commit (for now) because it is the one that introduces unwanted formatting changes:
|
4a274a9
to
16f46c3
Compare
5cc8dd7
to
a3cfd80
Compare
Thanks for cleaning it up. It's still unclear to me what this checks for or why it is so complicated. We should first create the test JSON files that fail in order to understand what a solution would be. Also, I'm sort of concerned that the exclusion of the "Allow for empty objects and empty arrays" commit hasn't resulted in a test failure... do we not have tests with empty objects and empty arrays? |
Still unclear to me too! I'm cleaning up the patch in the hope of understanding what #80 is supposed to fix. Then we can write a relevant test. Then perhaps we can suggest simpler code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DimitriPapadopoulos I see your comment here about parsers being more lenient than linters. I didn't realize this is the case; today I learned this from you!
My goal with these changes is to parse AND lint ECMA-404
JSON which doesn't strictly accept trailing commas (like the example below).
I appreciate you creating this cleaned-up PR. Also, thank you for the review + suggestions on #80. I will happily add your suggestions. Can I be given permission to edit this branch?
Still unclear to me too! I'm cleaning up the patch in the hope of understanding what #80 is supposed to fix. Then we can write a relevant test. Then perhaps we can suggest simpler code.
Do these logs help clarify my goal?
$ cat ../tests/invalid-0011.json # an example relevant test
{
"a": "b",
"c": "d",
"foo": [
"a",
],
"trailing-comma": {},
}
$ git checkout master && gcc -o test_json -I.. test_json.c ../json.c -lm && ./test_json ../tests/invalid-0011.json # This parses successfully with trailing commas in objects/arrays.
Already on 'master'
Your branch is up to date with 'origin/master'.
{
"a": "b",
"c": "d",
"foo": [
"a",
],
"trailing-comma": {},
}
--------------------------------
object[0].name = a
string: b
object[1].name = c
string: d
object[2].name = foo
array
string: a
object[3].name = trailing-comma
$ git checkout rework && gcc -o test_json -I.. test_json.c ../json.c -lm && ./test_json ../tests/invalid-0011.json # I desire this to fail because linting fails
Switched to branch 'rework'
{
"a": "b",
"c": "d",
"foo": [
"a",
],
"trailing-comma": {},
}
--------------------------------
Unable to parse data
To this review, I added the content from the d63b9d8 Allow for empty objects and empty arrays
commit which was excluded from the Draft PR. These lines fix the fact that the trailing_garbage
function+invocation broke empty object/array parsing. Also trailing_garbage
can probably be renamed to trailing_comma
(%s/trailing_garbage/trailing_comma/g
) because commas are the only reserved character which can wind up at the end of objects/arrays and end up with this successful parsing.
Because I desire a version of this parser which also does this particular linting, have you already thought of a different (improved) strategy to achieve this goal? I am curious to see any improvements on my attempt.
I think it's best if you can :
|
Co-authored-by: Thad Megow <[email protected]>
44aaf1d
to
e40f254
Compare
That being said, note that json-parser is defined as a "very low footprint JSON parser", so I don't know if the changes required for the linter will be applied. I guess it depends on the footprint of the additional code. In any case the decision does not belong to me. |
@DimitriPapadopoulos I created #156 , may I request a review? Perhaps this draft can be closed. |
Superseded by #156. |
Initial attempt to rework and understand #80.