fix: decode escaped JSON Pointer tokens in ensurePathExists#221
Open
Yanhu007 wants to merge 1 commit intoevanphx:masterfrom
Open
fix: decode escaped JSON Pointer tokens in ensurePathExists#221Yanhu007 wants to merge 1 commit intoevanphx:masterfrom
Yanhu007 wants to merge 1 commit intoevanphx:masterfrom
Conversation
ensurePathExists used decodePatchKey for get operations but passed the raw (encoded) path token to add operations. This caused keys containing ~1 (escaped /) to be stored with the encoded form instead of the decoded form, breaking nested path creation. For example, path "/with~1slash/nested" should create a key "with/slash" but was creating "with~1slash". Decode the path token before passing to add. Add regression test. Fixes evanphx#217
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #217
Problem
EnsurePathExistsOnAddfails when the path contains escaped characters like~1(JSON Pointer encoding for/):{"op": "add", "path": "/with~1slash/nested", "value": "baz"}This should create
{"with/slash": {"nested": "baz"}}but instead fails with:Root Cause
ensurePathExistsusesdecodePatchKey(part)when callingget()to look up existing keys, but passes the raw (encoded)parttoadd()when creating new intermediate objects. Thegetlooks for"with/slash"(decoded) butaddcreates"with~1slash"(encoded), so subsequent lookups fail.Fix
Decode the path token with
decodePatchKey()before passing toadd(), consistent with theget()call.Added regression test for escaped slash in nested path with EnsurePathExistsOnAdd.
All existing tests pass.