Skip to content

fix(patch): send JSON patches with slashes and unicode unescaped - #44

Merged
ChiragAgg5k merged 1 commit into
mainfrom
fix/patch-unescaped-slashes
Nov 12, 2026
Merged

ChiragAgg5k merged 1 commit into
mainfrom
fix/patch-unescaped-slashes

Conversation

@ChiragAgg5k

Copy link
Copy Markdown
Member

The API server compares a JSON patch test op's strings by their encoded bytes. PHP's default json_encode writes \/, so any test on a value containing a path never matched and the patch was refused with 422 Invalid.

// before
json_encode($operations, JSON_THROW_ON_ERROR);
// after (same as toJsonPayload already does for slashes)
json_encode($operations, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

Same for toJsonMergePatchPayload.

Found live: edge's sweep tests a StatefulSet's initContainers (whose command contains /var/run/mysqld) before replacing them; every tick got 422. The identical payload with slashes unescaped passes a server dry-run.

Tests in PatchPayloadTest: a test op with paths and non-ASCII stays verbatim; a merge patch keeps a/b; the pinned scalar case now expects unescaped paths. All three fail without the fix.

The API server compares a JSON patch test operation's strings by their encoded bytes, so PHP's default \/ never matched a stored / and any test on a value containing a path (an init container's command, a mount path) was refused with 422 Invalid. toJsonPayload already used JSON_UNESCAPED_SLASHES; the patch encoders now match it, and keep unicode verbatim for the same reason.
@appwrite

appwrite Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

This changes JSON Patch and JSON Merge Patch payload serialization to emit slashes and Unicode characters without JSON escapes. The payload tests now check literal paths, script strings, non-ASCII values, and merge-patch annotations.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
src/Kinds/K8sResource.php Adds unescaped slash and Unicode flags to JSON Patch and Merge Patch payload encoding.
tests/PatchPayloadTest.php Updates serialization expectations and adds coverage for slash and Unicode payloads.
🔇 Filtered out · 1

Findings Hansi considered but did not post.

Finding Why
Encoding escapes cannot cause JSON Patch test mismatches Verifier: The finding's premise is wrong. Kubernetes applies JSON Patch with evanphx/json-patch. As I remember it, that library's test operation compares scalar values by their raw bytes (bytes.Equal on the compacted raw JSON). I did not check this in the sandbox. So \/ and \u00e9 do not match a stored / and é, and the unescaped flags are a plausible fix. The change itself is harmless and matches its stated intent.

Reviewed bd0719c · Details · Comment @appwrite review to re-run, or mention @appwrite with a question.

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@ChiragAgg5k
ChiragAgg5k merged commit 8c7dd78 into main Nov 12, 2026
4 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.

1 participant