MarcosLopezC / LightJson

A simple JSON library for C#.
MIT License
60 stars 21 forks source link

Error position reported by TextScanner.Assert is off by one #34

Closed sharwell closed 7 years ago

sharwell commented 7 years ago

Code:

JsonValue.Parse("trUe");

Expected result: Error at line 0, column 2

Actual result: Error at line 0, column 3

Cause: TextScanner.Assert calls TextScanner.Read before validating the character, which causes the position to move forward by one. The current position needs to be stored in a local variable before calling Read so it can be used for positioning in the event of an error.

🔗 This was originally found in DotNetAnalyzers/StyleCopAnalyzers#2406.

sharwell commented 7 years ago

:memo: I found several more cases of this in my tests for JsonReader, which you'll find in the linked pull request (I haven't pushed the change containing these, but you'll see them later tonight in a commit with the title "Add tests for JsonReader").

MarcosLopezC commented 7 years ago

This issue is fixed by commit 2ec145b5a95284994dc1f5c5191f4db053b09ca4