Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Conversation

DimitriPapadopoulos
Copy link
Contributor

Initial attempt to rework and understand #80.

@DimitriPapadopoulos
Copy link
Contributor Author

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:

  • d63b9d8 Allow for empty objects and empty arrays

@DimitriPapadopoulos DimitriPapadopoulos force-pushed the rework_tmegow branch 2 times, most recently from 4a274a9 to 16f46c3 Compare November 5, 2021 08:32
@DimitriPapadopoulos DimitriPapadopoulos changed the title Check for trailing garbage inside json Check for trailing garbage inside json (rework #80) Nov 5, 2021
@DimitriPapadopoulos DimitriPapadopoulos force-pushed the rework_tmegow branch 3 times, most recently from 5cc8dd7 to a3cfd80 Compare November 5, 2021 08:54
@LB--
Copy link
Member

LB-- commented Nov 6, 2021

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?

@DimitriPapadopoulos
Copy link
Contributor Author

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.

Copy link

@tmegow tmegow left a 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.

@DimitriPapadopoulos
Copy link
Contributor Author

I think it's best if you can :

  • remove all formatting changes from the master branch of tmegow/json-parser, so that the intent of the patch is clear and not lost in the noise from the formatting changes,
  • then move these changes to a specific branch in your repo, such as lint or trailing_garbage,
  • apply any additional changes,
  • update your master branch from upstream,
  • rebase on master because there have been changes since 2019.

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented Dec 7, 2021

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.

@tmegow
Copy link

tmegow commented Dec 7, 2021

@DimitriPapadopoulos I created #156 , may I request a review? Perhaps this draft can be closed.

@DimitriPapadopoulos
Copy link
Contributor Author

Superseded by #156.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants