Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly format normalized path names (#113)
The RFC defines how to [format normalized path names]. Notably, it defines the escape character as `ESC normal-escapable`, but doesn't define `ESC` in that section. It is, however, defined for [name selector syntax] as `%x5C; \ backslash`. I'm therefore reasonably sure that the current behavior of serde_json_path when formatting normalized paths is incorrect, as it results in no escaping of `'` at all. For example, using [the sandbox] to select `$.*` from `{"O'Reilly": true}` returns ```json [ { "loc": "$['O'Reilly']", "node": true } ] ``` I worked this out while building the location feature into [Go jsonpath] (many thanks for the inspiration in your crate!). This [playground link] shows what I believe to be the correct escaping (doubled for inclusion in JSON): ``` json [ { "node": true, "path": "$['O\\'Reilly']" } ] ``` So expand `Display for PathElement` to properly format characters strictly according to the spec. Iterate over each character in a name and escape exactly the characters it defines to be escaped. [format normalized path names]: https://www.rfc-editor.org/rfc/rfc9535#section-2.7 [name selector syntax]: https://www.rfc-editor.org/rfc/rfc9535#name-syntax-3 [the sandbox]: https://serdejsonpath.live [Go jsonpath]: https://github.com/theory/jsonpath [playground link]: https://theory.github.io/jsonpath/?p=%2524.*&j=%257B%2522O%27Reilly%2522%253A%2520true%257D&o=1
- Loading branch information