Repository navigation
fix(clipboard): truncate the preview on a rune boundary - #35
Merged
Merged
Conversation
- back the preview cut off to the start of the last partial rune, so the preview is always valid UTF-8 - DuckDB rejects an invalid-UTF-8 VARCHAR bind, which failed the insert and dropped the whole clipboard event for any copy over 8 KiB containing multi-byte characters - add TestGeneratePreivewKeepsPreviewValidUTF8: three- and four-byte runes, an aligned cut and pure ASCII; the last two also guard against over-trimming
Owner
|
Thanks for the pull request! |
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.
Problem
The preview is capped at 8 KiB, but the cap was applied with a plain byte cut
(
w.buf.Truncate(maxPreviewLength)). When that cut lands inside a multi-byterune, the preview ends in a partial UTF-8 sequence.
DuckDB rejects an invalid UTF-8 string bound as a
VARCHAR, sofails and the daemon only reports:
The transaction rolls back and the whole clipboard event is lost:
yankd listnever shows it.
Because CJK runes are 3 bytes,
8192 % 3 == 2, so for Chinese content the cutalmost always splits a rune. ASCII copies are unaffected — that is why only some
copies were lost. Reported case: copying a long Chinese markdown document from a
web page.
Change
runeSafeLength(buf, n), which backs the cut off to the start of the lastpartial rune, so the preview is always valid UTF-8.
only entries whose
IsTextis true are appended to it.Tests
TestGeneratePreivewKeepsPreviewValidUTF8covers:fix ever over-trims by a fixed offset
The first two fail without the fix and pass with it.
Reproducing on the unfixed version
Only payloads larger than 8 KiB are affected, so any clipboard content above
that size with multi-byte characters reproduces it:
With the unfixed build and the daemon running:
ERRO failed to insert data ... could not bind parameteryankd listA browser copy of the same text also hits it — a browser additionally advertises
escaped
\uXXXXvariants of the text, which only moves the cut point, so if aparticular document happens to be aligned, add or remove one ASCII character and
copy again.