Skip to content

Fix JSON Patch move and copy array targets#136

Merged
jg-rp merged 2 commits into
jg-rp:mainfrom
gaoflow:fix-json-patch-move-copy-array-targets
Jul 20, 2026
Merged

Fix JSON Patch move and copy array targets#136
jg-rp merged 2 commits into
jg-rp:mainfrom
gaoflow:fix-json-patch-move-copy-array-targets

Conversation

@gaoflow

@gaoflow gaoflow commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • apply the existing JSON Patch add target semantics to move and copy operations
  • support the - array target for appending moved or copied values
  • reject target indexes greater than the array length instead of silently appending them

Problem

RFC 6902 defines move as a removal followed by add, and copy as add using the source value. The implementation handled their destinations separately with list.insert(), bypassing the boundary behavior fixed for add in #118. As a result, an array target ending in - leaked a native ValueError, while an index greater than the array length was silently clamped to the end by Python.

Delegating the destination step to OpAdd keeps these three standard operations on one target implementation while preserving the deep copy required by copy.

Testing

  • 2828 passed, 1 skipped
  • ruff check .
  • mypy (86 source files)

@jg-rp

jg-rp commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Thanks @gaoflow,

I've refactored it a little to avoid the extra OpAdd instantiation, favoring a standalone private _add() function that OpAdd, OpMove and OpCopy use.

We should probably do a similar thing with a _remove() function in a future PR.

@jg-rp
jg-rp merged commit 07e0b32 into jg-rp:main Jul 20, 2026
14 checks passed
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.

2 participants