Repository navigation
Decode UTF-16 text in clipboard history - #7249
Conversation
531e6b6 to
fbc7ca3
Compare
There was a problem hiding this comment.
Pull request overview
Adds UTF-16 clipboard decoding and temporary-file cleanup. It also includes unrelated server/backup planning documents.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Changes:
- Detects and converts UTF-16LE/BE clipboard text.
- Adds clipboard regression tests.
- Adds unrelated plans, mockups, and Markdown guidance.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
shell/plugins/clipboard/capture.sh |
Implements UTF-16 detection, conversion, and cleanup. |
test/shell.d/clipboard-test.sh |
Tests UTF-16LE decoding and cleanup. |
AGENTS.md |
Adds Markdown line-wrapping guidance. |
plans/server.md |
Adds the Omarchy Server plan. |
plans/backup.md |
Adds the backup feature plan. |
plans/images/server-login.svg |
Adds a login mockup. |
plans/images/server-menu.svg |
Adds a menu mockup. |
plans/images/server-update.svg |
Adds an update-screen mockup. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| capture_output=$(printf '%s' 'UTF-16 clipboard — fixed' | iconv -f UTF-8 -t UTF-16LE | XDG_RUNTIME_DIR="$TMPDIR" XDG_STATE_HOME="$TMPDIR/state" PATH="$TMPDIR/bin:$PATH" "$ROOT/shell/plugins/clipboard/capture.sh" text) | ||
| [[ $capture_output == '{"type":"text","text":"UTF-16 clipboard — fixed"}' ]] || fail "clipboard capture decodes UTF-16LE text" | ||
| pass "clipboard capture decodes UTF-16LE text" | ||
|
|
||
| capture_output=$(printf 'A' | iconv -f UTF-8 -t UTF-16LE | XDG_RUNTIME_DIR="$TMPDIR" XDG_STATE_HOME="$TMPDIR/state" PATH="$TMPDIR/bin:$PATH" "$ROOT/shell/plugins/clipboard/capture.sh" text) | ||
| [[ $capture_output == '{"type":"text","text":"A"}' ]] || fail "clipboard capture decodes single-character UTF-16LE text" | ||
| pass "clipboard capture decodes single-character UTF-16LE text" |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
shell/plugins/clipboard/capture.sh:74
- The NUL-position heuristic can silently reverse endianness when a NUL belongs to the character rather than padding. For example, BOM-less UTF-16LE
😀is3d d8 00 de; this satisfies the BE branch, andiconvsuccessfully produces㷘Þ, so the raw fallback never runs. Only treat NULs paired with plausible padded single-byte characters as endian evidence (or leave ambiguous payloads unchanged), and add this case to the regression tests.
if (even_nuls >= 1 && even_nuls * 2 >= pairs && odd_nuls * 10 <= even_nuls)
print "UTF-16LE"
else if (odd_nuls >= 1 && odd_nuls * 2 >= pairs && even_nuls * 10 <= odd_nuls)
print "UTF-16BE"
test/shell.d/clipboard-test.sh:305
- This assertion only covers normal completion; the newly added HUP/INT/TERM cleanup path is never exercised. Add a test that keeps stdin open, waits for
clipboard-text.*to appear, terminates the capture process, and verifies the directory is removed so signal cleanup cannot regress unnoticed.
if compgen -G "$TMPDIR/clipboard-text.*" >/dev/null; then
fail "clipboard capture removes temporary text payloads"
fi
fbc7ca3 to
94ec33e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (2)
test/shell.d/clipboard-test.sh:295
- The committed regressions exercise only BOM-less UTF-16LE, leaving the new BOM and UTF-16BE branches unprotected even though both are part of the capture contract. Add persistent cases for BOM-tagged text and BOM-less UTF-16BE.
capture_output=$(printf '%s' 'UTF-16 clipboard — fixed' | iconv -f UTF-8 -t UTF-16LE | XDG_RUNTIME_DIR="$TMPDIR" XDG_STATE_HOME="$TMPDIR/state" PATH="$TMPDIR/bin:$PATH" "$ROOT/shell/plugins/clipboard/capture.sh" text)
shell/plugins/clipboard/capture.sh:61
unpack("C*", $raw)materializes one Perl scalar per input byte, so a large text clipboard can amplify memory usage by orders of magnitude and OOM the capture process. Count the two byte positions directly while retaining only$raw.
my @bytes = unpack("C*", $raw);
94ec33e to
3d8130e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
shell/plugins/clipboard/capture.sh:61
decodemay destructively consume its source wheneverCHECKis nonzero unlessLEAVE_SRCis set. If UTF-16 decoding processes a valid prefix and then croaks on malformed trailing data,$rawcan contain only the unconsumed suffix, so the fallback on the next line no longer preserves the original payload. Keep the source intact for the fallback; a valid-prefix-plus-truncated-tail test would also exercise this case.
my $text = $encoding ? eval { decode($encoding, $raw, FB_CROAK) } : undef;
(cherry picked from commit 006460a)
Summary
Testing
bash test/shell.d/clipboard-test.shbash -n shell/plugins/clipboard/capture.sh test/shell.d/clipboard-test.shgit diff --checkThe implementation incorporates Codex High review findings: strict conservative detection replaces the permissive heuristic, and constant-overhead regex scanning replaces per-byte Perl scalar expansion.