-
-
Notifications
You must be signed in to change notification settings - Fork 2
The JsonPathDetector
class does not handle empty objects correctly
#1
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
Comments
I have implemented a unit test and fix for this issue, but cannot push it due to insufficient access. |
Unit test that illustrates the problem. This test will currently fail.
|
Pull request #2 has been created to address this issue. |
Brilliant, thanks for the report, the detailed explanation and the fix! I've released v1.2.1 containing the fix. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
JsonPathDetector
class handles JSON objects and arrays slightly differently, due to the need to recognize an object's property keys. To handle this, theJsonPathDetector
state machine uses an additional"pending"
state when processing objects. During the"pending"
state, no path item has been pushed for properties of the object.When the closing brace of an empty object is encountered, the state is still
"pending"
since no properties have been seen. The current implementation of the state machine currently assumes that a path item has been pushed. It therefore incorrectly pops the key of the enclosing object or array.Consider the following JSON fragment:
When a
JsonPathDetector
object encounters the closing brace of the"inner"
object, the path is just[ "outer", "inner" ]
because no nested properties have been found. Ordinarily the key of the last nested property would be popped, but the"inner"
key is popped instead. TheJsonChunk
is therefore incorrectly given an[ "outer" ]
path. The paths of all subsequentJsonChunk
objects will then be incorrect.The text was updated successfully, but these errors were encountered: