Fixes JsonPathDetector
path for empty objects
#2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These changes fix the
JsonPathDetector
class, which is not handling paths correctly for empty objects.The original implementation uses a state machine that handles objects and arrays slightly differently, due to the need to recognize an object's nested property keys. To handle this, the state machine uses a special
"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 original implementation of the state machine assumes that a path item for a nested property has been pushed. Since no nested property has been encountered, no additional key has been pushed and the key of the enclosing object or array is popped instead.Consider the following JSON fragment:
These changes fix the state machine to check the current state before conditionally popping an item from the path. The also add unit tests to check the special cases of empty objects and arrays.