Skip to content

Fixes JsonPathDetector path for empty objects #2

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

Merged
merged 1 commit into from
Jun 23, 2024

Conversation

tetrachromium
Copy link
Contributor

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:

{
  "outer": {
    "inner": { // Has path [ "outer", "inner" ]
    } // Should also have path [ "outer", "inner" ], but has path [ "outer" ]
  }
}

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.

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.

2 participants