Repository navigation
Reject invalid CLI patches before modifying the input file - #246
Merged
stefankoegl merged 1 commit intoNov 2, 2026
Merged
Conversation
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.
On 1.39,
jsonpatch -ican remove a field even though the patch document is invalid. Starting with{"keep":7}, the following input exits successfully and writes{}:[{"op":"test","op":"remove","path":"/keep","value":13}]The CLI first uses the standard JSON decoder, which keeps the last
op. It also accepts a top-level JSON string containing an encoded patch array because the string is decoded a second time. Passing the same raw inputs toapply_patchalready raisesInvalidJsonPatch. A patch must be an array, and an operation must have exactly oneopmember (RFC 6902, sections 3–4 and example A.13).Pass the original patch text to the existing library decoder. Regression tests exercise both invalid inputs via a file and stdin and check that the original file is preserved byte for byte.
All four cases failed before the fix and passed afterward. Ran 235 unit and documentation tests, 21 property tests, and the project's critical flake8 check on Python 3.12.16.
Prepared with AI assistance.