-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
JsonNode.GetPath()
doesn't consider character escaping
#83547
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsDescriptionThe Reproduction Steps
Expected behaviorReturns Actual behaviorReturns Regression?Unknown Known WorkaroundsNone. ConfigurationSeems to happen everywhere. dotnetfiddle, Linux. Will update with more details in a comment. Other informationOriginally reported json-everything/json-everything#406.
|
The specific source code in question is the following: runtime/src/libraries/System.Text.Json/src/System/Text/Json/Nodes/JsonObject.cs Lines 131 to 138 in a396d6e
While it actively looks for special characters to use indexer syntax ( |
I should also mention that perhaps JSON Path is the wrong syntax to use for identifying a single location within a JSON tree. JSON Pointer is more well-suited for that. |
☝️ I'm adding |
Description
The
JsonNode.GetPath()
generally does well for C#-valid property names, but any string is valid as a key in JSON, and when a key has characters that need escaping, nothing happens and you get an invalid (unparsable) JSON Path as a result.Reproduction Steps
Expected behavior
Returns$.$defs['foo[\'bar']
.Returns
$['$defs']['foo[\'bar']
.$defs
is not valid as a shorthand property name, so it needs to be in bracketed syntax.Actual behavior
Returns
$.$defs['foo['bar']
.Regression?
Unknown
Known Workarounds
None.
Configuration
Seems to happen everywhere. dotnetfiddle, Linux.
Will update with more details in a comment.
Other information
Originally reported json-everything/json-everything#406.
The text was updated successfully, but these errors were encountered: