fix(doc): capture line-wrapped base64 in clipboard data URI regex#586
Merged
fangshuyu-768 merged 1 commit intofeat/media-insert-clipboardfrom Apr 21, 2026
Merged
Conversation
HTML and RTF clipboard content commonly folds base64 payloads at
76 chars (standard MIME folding). The previous character class
[A-Za-z0-9+/\-_]+=* stopped at the first \n, so the downstream
strings.Fields normalisation was a no-op (nothing to strip) and
extractBase64ImageFromClipboard silently uploaded a truncated
payload whose 8-byte prefix happened to pass hasKnownImageMagic.
Extend the class to include \s so the Fields strip actually has
whitespace to remove before base64 decoding. Terminators (", <,
), ;) remain outside the class so the match still ends at the
URI boundary.
Add TestReBase64DataURI_LineWrapped covering \n, \r\n, and \t
folds, full round-trip byte-equality, and the terminator-boundary
invariant so any future regression trips a failing test.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Summary
Targeted fix for PR #508 addressing the review thread at #discussion_r3116012669: the
strings.Fieldsnormalisation added inadac5bfis a no-op, and line-wrapped base64 payloads are silently uploaded as corrupt 8-byte "PNGs".Root cause
reBase64DataURIhas character class[A-Za-z0-9+/\-_]+=*, which excludes whitespace. For a 76-char-folded HTML payload — standard MIME base64 folding, very common in real clipboards (Chrome, Safari, Feishu copy-image-as-HTML) — the regex stops at the first\n, som[2]is already truncated by the time thestrings.Fieldsstrip runs.Fieldsthen normalises a string that by construction has no whitespace, which does nothing.Concretely, a payload like:
matches only
iVBORw0KGgo(11 chars), decodes to exactly the 8-byte PNG signature89 50 4E 47 0D 0A 1A 0A, passeshasKnownImageMagic, and ends up being uploaded as a truncated 8-byte "PNG" block. The user sees a broken image.Fix
Extend the character class to include
\s, so the existingstrings.Fieldsstrip on line 144 ofclipboard.goactually has whitespace to normalise. Terminators (",<,),;) stay outside the class, so the match still ends at the URI boundary.Test plan
go test ./shortcuts/doc/... -count=1passes (newTestReBase64DataURI_LineWrappedadded)go vet ./shortcuts/doc/...cleangofmt -lclean\n,\r\n, and\tthrough the regex, asserts full round-trip byte-equality afterstrings.Fieldsnormalisation, and confirms the regex does not run past the">attribute terminator (catches an over-permissive regression in the other direction).TestReBase64DataURI_Match,TestReBase64DataURI_URLSafeMatch,TestReBase64DataURI_NoMatch,TestExtractBase64ImageFromClipboard_WithFakeOsascript— still pass.Notes
feat/media-insert-clipboardso this lands as part of PR feat(doc): add --from-clipboard flag to docs +media-insert #508 before it merges tomain.🤖 Generated with Claude Code