docs: state the invariant that makes the media field decode safe - #633
Draft
jkmassel wants to merge 1 commit into
Draft
docs: state the invariant that makes the media field decode safe#633jkmassel wants to merge 1 commit into
jkmassel wants to merge 1 commit into
Conversation
`formFields` decodes each non-file form value as UTF-8, which substitutes U+FFFD on malformed input. That is lossless today, but only because of an invariant nothing in the code states or enforces: the sole client is the editor's browser FormData. The server binds to loopback behind a per-session token; a FormData string value is a USVString, already well-formed at append time; and its only way to carry arbitrary bytes is a Blob, which always gets a filename and is filtered out of `extraParts`. Write that down on both platforms, including the part that makes it matter — if it stops holding, the two platforms are lossy *differently*, so there is no single behavior that could be documented instead. Relaxing each platform's filename filter demonstrates it: for `ED A0 80` Swift yields three replacement characters under its maximal-subpart rule where Java's decoder yields one. Cover the partition rather than the decode, since the partition is what makes the invariant true: a request carrying a second, Blob-shaped part whose bytes are not valid UTF-8 must not surface that part in `fields`. A second test pins the other half — valid UTF-8 (emoji, non-Latin scripts) round-trips exactly, so real captions are unaffected. Both fail when the filter is relaxed, so neither is vacuous. Neither asserts what becomes of that second part — it is currently dropped rather than relayed, which is a separate open question. Also reword the raw-bytes comment on the re-encode path. "So a non-UTF-8 value is forwarded verbatim" read as though malformed values were expected, which made the two delivery paths look contradictory. The actual hazard is the failable decode returning nil and an obvious `?? ""` dropping the whole value; the reason to keep bytes is that the re-encode should stay byte-identical to the passthrough it stands in for. Finally, restore `attachmentId`'s doc comment, which an earlier commit in this series orphaned onto `formFields` when it inserted the helper above it.
XCFramework BuildThis PR's XCFramework is available for testing. Add the following to your .package(url: "https://github.com/wordpress-mobile/GutenbergKit", branch: "pr-build/633")Built from 3b6ad45 |
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.
Stacked on #632. Last of ten PRs splitting #621.
What?
Documents why
formFields' UTF-8 decode is lossless, and covers the partition that makes it so.Why?
formFieldsdecodes each non-file form value as UTF-8, which substitutes U+FFFD on malformed input. That is lossless today, but only because of an invariant nothing in the code states or enforces: the sole client is the editor's browserFormData.FormDatastring value is aUSVString, already well-formed atappendtime.extraParts.Worth writing down because if it stops holding, the two platforms are lossy differently — so there is no single behavior that could be documented instead. Relaxing each platform's filename filter demonstrates it: for
ED A0 80, Swift yields three replacement characters under its maximal-subpart rule where Java's decoder yields one. Both observed, not inferred.How?
formFields, both platforms.?? ""dropping the whole value; the reason to keep bytes is that the re-encode should stay byte-identical to the passthrough it stands in for.attachmentId's doc comment, which feat: add MediaUploader, for a host that owns the whole upload #628 orphaned ontoformFieldswhen it inserted that helper above it.Testing Instructions
Cover the partition rather than the decode, since the partition is what makes the invariant true: a request carrying a second, Blob-shaped part whose bytes are not valid UTF-8 must not surface that part in
fields. A second test pins the other half — valid UTF-8 (emoji, non-Latin scripts) round-trips exactly.swift test— host suite green:Gutenberg:testDebugUnitTestgreenNeither test asserts what becomes of that second part — it is currently dropped rather than relayed, which is a separate open question.