Skip to content

bug: jsonpatch does not play nice with "/" in dict keys#165

Draft
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-94
Draft

bug: jsonpatch does not play nice with "/" in dict keys#165
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-94

Conversation

Copy link

Copilot AI commented May 27, 2025

Addresses the issue where / characters in dictionary keys cause unexpected JSON Patch paths (e.g. /~1fields~1test instead of /fields/test). This is correct behavior per RFC 6901, but users who intend their slash-containing keys as path separators can now use the new expand_slash_keys() utility to convert their flat dict to a nested structure before patching.

Changes Made

  • New utility function expand_slash_keys() in jsonpatch.py: converts a flat dictionary with slash-separated path-like keys into a nested dictionary, so that make_patch generates human-readable JSON Pointer paths. Raises ValueError if two keys produce conflicting paths (e.g. 'a' and 'a/b' both present).
  • Tests: Added 6 unit tests for expand_slash_keys covering simple leading-slash keys, mixed slashed/plain keys, deep nesting, no-slash passthrough, make_patch integration, and the conflict error case.
  • CI fix: Corrected --source=jsonpointer--source=jsonpatch in test.yaml, removed the unsupported Python 2.7 entry from the test matrix, and added Python 3.12.

Testing

  • ✅ All 124 tests pass (coverage run --source=jsonpatch tests.py)
  • ✅ No CodeQL security alerts

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

@stefankoegl
Copy link
Owner

@copilot fix failing tests

Copy link
Author

Copilot AI commented Mar 20, 2026

@copilot fix failing tests

Done in feb60bf. Changes made:

  1. Added expand_slash_keys() utility in jsonpatch.py — converts flat dicts with slash-separated path-like keys into nested dicts, so make_patch produces readable JSON Pointer paths (e.g. {'/fields/test': '123456'}{'fields': {'test': '123456'}}). Raises ValueError on conflicting key paths.

  2. Added 6 tests for expand_slash_keys covering: simple leading-slash key, mixed slashed/plain keys, deep nesting, no slashes, make_patch integration, and the conflict error case.

  3. Fixed test.yaml CI: corrected --source=jsonpointer--source=jsonpatch (this repo is jsonpatch, not jsonpointer), removed Python 2.7 from the matrix (not supported by actions/setup-python@v4), and added Python 3.12.

Copilot AI changed the title [WIP] bug: jsonpatch does not play nice with "/" in dict keys bug: jsonpatch does not play nice with "/" in dict keys Mar 20, 2026
Copilot AI requested a review from stefankoegl March 20, 2026 22:00
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