Skip to content

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