Skip to content

Fix: incorrect ~1 decoding in decode_pointer_inplace#1019

Open
CyberpsychoJacob wants to merge 2 commits into
DaveGamble:masterfrom
CyberpsychoJacob:master
Open

Fix: incorrect ~1 decoding in decode_pointer_inplace#1019
CyberpsychoJacob wants to merge 2 commits into
DaveGamble:masterfrom
CyberpsychoJacob:master

Conversation

@CyberpsychoJacob
Copy link
Copy Markdown

Bug:
decode_pointer_inplace in cJSON_Utils.c incorrectly decoded the ~1
escape sequence (RFC 6901 JSON Pointer, representing /).
The write target was off by one:

/* before */
decoded_string[1] = '/';
/* after */
decoded_string[0] = '/';

This left the original ~ in place, producing ~/ instead of /. As a
result, any JSON Patch operation (add, remove, replace, move, copy)
whose "path" contained a ~1 sequence would silently target the wrong key.

Fix:
Changed decoded_string[1] to decoded_string[0] so the decoded / is
written to the correct position.

A unit test has been added to tests/misc_utils_tests.c that applies a
replace patch targeting a key with a literal / in its name via a ~1
path, and verifies the correct key is updated.

The ~1 escape sequence (RFC 6901 JSON Pointer, representing '/') was
writing the decoded '/' to decoded_string[1] instead of decoded_string[0],
leaving the original '~' in place and producing '~/' instead of '/'.

This caused any JSON Patch operation whose path contained a ~1 sequence
to silently target the wrong key, making ADD/REMOVE/REPLACE/MOVE/COPY
operate on an incorrect node without error.
Verifies that cJSONUtils_ApplyPatches correctly resolves ~1 escape
sequences in patch paths to a literal '/' when targeting object keys
that contain a forward slash.
@CyberpsychoJacob CyberpsychoJacob changed the title Fix incorrect ~1 decoding in decode_pointer_inplace Fix: incorrect ~1 decoding in decode_pointer_inplace May 13, 2026
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.

1 participant