Skip to content

Encode transcode clipboard file URIs - #13360

Open
HerrStolzier wants to merge 2 commits into
omacom:quattrofrom
HerrStolzier:fix/transcode-clipboard-uris
Open

HerrStolzier wants to merge 2 commits into
omacom:quattrofrom
HerrStolzier:fix/transcode-clipboard-uris

Conversation

@HerrStolzier

Copy link
Copy Markdown
Contributor

Problem

omarchy transcode builds its clipboard URI by concatenating file:// with an unescaped output path. The encode succeeds, but URI consumers can resolve that text to a different file: # becomes a fragment, ? becomes a query, and a literal %20 in a filename becomes a space.

I reproduced this with actual ImageMagick/FFmpeg conversions and GIO's g_file_new_for_uri() / g_file_get_path(), while substituting only clipboard delivery and notifications. For example, the generated shot#1-low.jpg was interpreted as shot, and shot%20-low.png as shot -low.png.

Change

Use Python's standard-library Path.resolve().as_uri() when building text/uri-list. This retains absolute/symlink resolution and percent-encodes the path. The Python invocation uses -I so it does not import a pathlib.py from the current directory.

The only production change is in copy_to_clipboard(). Encoder arguments, output naming, menus, and clipboard MIME type are unchanged. No migration is needed.

Verification

Base: e1614f2bdb94f7df11eda072644b31e1e118f1ba. The complete uploaded Git archive reconstructed tree 1dbe5d3de4f8e7b712290332f59518ddb88cda37, matching that source tree. Tests ran unprivileged in an isolated, headless Debian 13 environment, with private HOME/tmp, read-only source/system directories, and no network or desktop-session sockets.

  • bash test/shell.d/transcode-clipboard-test.sh: 15 success records, exit 0. Covers plain paths, reserved characters, literal percent escapes, spaces, UTF-8, newline/tab, apostrophes, parent directories, relative/symlink paths, Python module shadowing, PNG/JPG/MP4/GIF outputs, and encoder/URI/clipboard failure paths. This uses the real command and substitutes media/clipboard/notification boundaries.
  • The same regression test fails against the unmodified command at the reserved-character case. It also passes with a temporary-directory path containing spaces and #, and with the system Python interpreter.
  • Actual media/GIO round trips: 0/4 correct paths before, 4/4 after (three images and one video). These tests use real encoders and an independent URI consumer, not a second call to pathlib as the oracle.
  • Mutation checks detect reverting the fix, dropping .resolve(), undoing %25 escaping, and removing -I. The import-isolation mutation was checked with Debian's system Python; the sandbox's virtualenv pre-imports pathlib, so it masks that particular mutation.
  • bash -n, git diff --check, and bin-style-test.sh pass.
  • ./test/all completed on both the untouched and changed trees. Both return 1: the CLI suite stops at the same existing VS Code theme assertion; 31 shell test files fail in both runs (262 files before, 263 after). The failing-file set, all 25 emitted not ok lines, and the 23-file skip set are identical. The new transcode suite passes in the full run. No unrelated tests were changed or suppressed.
Full-suite failures present on both trees in this environment
ascii-test.sh
bar-text-color-test.sh
config-test.sh
dev-link-test.sh
hw-hybrid-gpu-test.sh
hw-nvidia-test.sh
hyprland-binding-conflicts-test.sh
hyprland-default-config-test.sh
hyprland-keyboard-layout-test.sh
hyprland-paths-test.sh
hyprland-qconsole-test.sh
hyprland-workspace-layout-test.sh
kernel-headers-migration-test.sh
keybindings-menu-test.sh
kitty-config-test.sh
locate-test.sh
mise-work-path-test.sh
neovim-remote-yanks-test.sh
omarchy-kernel-migration-test.sh
passwordless-grant-lifecycle-test.sh
powerprofiles-set-test.sh
provision-user-test.sh
setup-security-sshd-test.sh
snapper-test.sh
ssh-reconnect-test.sh
sshd-hardening-migration-test.sh
toggle-input-device-test.sh
unowned-system-paths-test.sh
update-lock-test.sh
update-stay-awake-security-test.sh
webapp-install-escaping-test.sh

Several require unavailable tools (for example Lua, updatedb, or mise), companion repositories, or capabilities unavailable in this headless environment; others are existing failing assertions. This is a baseline comparison, not a claim that every failure is environmental or that the full suite is green.

Scope and related work

No live Wayland clipboard delivery or graphical paste test was performed. The byte payload and actual GIO path interpretation were tested instead. No real package transactions, boot changes, or desktop configuration changes were performed.

I checked the current omarchy-transcode versions in #12135 and #6698: both still concatenate an unescaped URI. They modify the same file for different features; this change is limited to clipboard URI construction and its regression coverage.

Developed and tested with AI assistance (ChatGPT).

Resolve output paths and percent-encode them before passing text/uri-list
to wl-copy, so reserved characters and literal percent escapes keep their
filesystem meaning.

Add regression coverage for image and video paths, UTF-8 and control
characters, relative symlinks, Python import isolation, and failure paths.
@llstrk

llstrk commented Sep 27, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: the URI fix is correct, and the new test catches the bug it targets. No issue was found in the production change within the tested scope. One point concerns coordination with open PR #12135: once both are merged, the new test no longer passes.

Verified by running the real base and head scripts (encoders, notifications and wl-copy stubbed) on 20 filenames and parsing the saved clipboard payload with GLib g_filename_from_uri, GIO g_file_new_for_uri, GTK's text/uri-list path, Qt QMimeData::urls() + toLocalFile(), Node's WHATWG URL with fileURLToPath, and the shell's clipboard history decoder:

Output name contains Base Head
#, ?, # in a parent directory, literal %20 misread by GLib, GIO, GTK, Qt and Node exact path in every consumer
literal %2F, bare % fails or misread in most consumers exact path in every consumer
newline payload splits into two entries exact path in every consumer
only A-Za-z0-9 _ . - ~ / in the whole path (e.g. screen recording names) exact path byte-for-byte same payload as base
non-UTF-8 byte (caf\xe9) wrong in every consumer %E9: exact in GLib, GIO and GTK; Qt, Node's fileURLToPath and the history decoder cannot represent it (also wrong on base)

Head was not worse than base for any tested name in any tested consumer.

Verified, also:

  • Test: passes 15/15 on head, including with a TMPDIR containing # and a space, and under test/shell. On base it fails at "reserved characters are encoded rather than interpreted as URI syntax". It also catches five mutations: -I removed, .resolve() removed, .absolute() in place of .resolve(), % left unencoded, and || true after the Python call.
  • python3: present on standard installs. uwsm, ufw, python-gobject and nautilus-python in install/omarchy-base.packages all depend on python, and other bin/ scripts already call python3.
  • resolve(): gives the same path as realpath -- for the output file, including relative paths through a symlinked directory.
  • Failure handling: if the Python step fails, the script stops before wl-copy and before the success notification.

New test fails when combined with #12135

The #13360 diff applies cleanly on top of #12135 (quality tiers), and #12135 does not touch copy_to_clipboard. In that combination #12135's own test still passes, but this PR's test fails at its first check:

#12135:        "Saved and copied to clipboard${size:+ ($size)}."  ->  "Saved and copied to clipboard (<1 MB)."
this test:     grep -Fxq 'Saved and copied to clipboard.'          ->  no match  ->  not ok - successful copy reports completion

With only that match relaxed, the file stops at the first video case: #12135 prompts for quality when no fourth argument is given, and this test has no omarchy-menu-select stub. The run caught this with a tripwire stub; with Omarchy's own scripts on PATH, the real menu would be called from inside the test. With the relaxed match plus a menu stub, all 15 checks pass, so the encoding fix itself survives the combination. From reading only: the negative checks for clipboard and URI-conversion failures run after the output file exists, so under #12135 a regressed success message would carry a size, ! grep -Fq 'Saved and copied to clipboard.' would not match it, and those two checks would pass without testing anything.

Impact: whichever of the two PRs lands second leaves test/shell.d/transcode-clipboard-test.sh failing until it is adjusted.

Suggested change: match the Saved and copied to clipboard prefix in both the positive and negative checks, and make the video cases answer the quality prompt: pass an explicit quality such as medium (the current command ignores a fourth argument), or add an omarchy-menu-select stub in $scratch/bin that prints medium. The stub variant was run and passes 15/15; the explicit-argument variant is from reading source. Tripwire stubs for omarchy-menu-file (and omarchy-menu-select, if the argument route is used) keep a real menu from ever opening inside the test. Open PR #6698 was also checked: its test and this one both pass when combined.

Note: wl-copy --type text/uri-list also offers the plain-text MIME types, so an app that pastes the plain-text type (as a terminal or plain text field may) now gets the encoded form (for example Gr%C3%BC%C3%9Fe-high.png) for names with spaces, non-ASCII or reserved characters. This is the correct URI text, but it may be visible to users (read from wl-clipboard source; no live paste was tested).

Optional test improvement: check_uri runs the command without || fail, so the -I and .resolve() mutations above end the file through set -e with no not ok line (the runner still reports the file as failed). Adding || fail "$description" after the bash "$ROOT/bin/omarchy-transcode" ... line names the failing case.


Review information

Test scope: PR test, mutations and payload parsing ran in an isolated command sandbox with Python 3.14.7, GLib 2.88.3 and Qt 6.11.2, with encoders, notifications and the clipboard stubbed. GTK 4.22.4's text/uri-list path was reproduced through the GLib calls it makes, and wl-clipboard 2.3.0 behaviour was read from source. Combinations with #12135 and #6698 were built locally from their current heads. Chromium/Electron handling was read from source only; Firefox was not examined. No live Wayland paste into a GUI application was performed, and no other Python version was run.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

Address llstrk's review on omacom#13360. Match the completion
message prefix in both positive and negative checks, answer only the
optional quality prompt in a stub, and reject unexpected menu requests.
Stub ffprobe so dummy media stays on the estimate fallback path.

Report named failures for unsuccessful transcodes and verify the injected
failure statuses, so an unrelated early menu error cannot satisfy a
negative test.

The 15 cases pass on the current command and a focused overlay of the
transcode command from omacom#12135 at b9535ec, including open
stdin and PTY runs. Fifteen mutation/error-injection checks are detected.
Full test/all runs before and after retain identical failing and skipped
file sets (31 failing and 23 with skips out of 263 shell test files), plus
the unchanged VS Code CLI assertion. No production code is changed.
@HerrStolzier

Copy link
Copy Markdown
Contributor Author

Thanks @llstrk — I reproduced both failures and addressed the test feedback in 40a1500.

The test now matches the completion-message prefix in both positive and negative checks, answers only the optional quality prompt with a medium stub, rejects other menu/file-picker calls, and stubs ffprobe. It also reports named failures and checks the injected failure exit codes, so an unrelated early error cannot satisfy a negative case. Production code is unchanged by this follow-up.

Verification: 15/15 cases pass with the current command and with the exact transcode command from #12135 at b9535ec3 plus this PR's URI change, including open-stdin and PTY runs. All 15 mutation/error-injection checks are detected, including size-suffixed false success messages in all three failure paths and unexpected menu calls. The #12135 check is a focused command overlay, not a full merge or a run of that PR's complete suite.

./test/all completed before and after this follow-up. Both have the same 31 failing shell files, 23 files with skips, and identical emitted failure assertions; the existing VS Code CLI assertion is unchanged. The clipboard suite passes in both full runs. No live clipboard or desktop paste was tested.

@llstrk

llstrk commented Sep 29, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Outcome: No defects found at 40a1500; both test points from the earlier review are resolved.

Earlier points, rechecked at 40a1500 (production code is unchanged since that review):

Earlier point Status
New test fails when combined with #12135 Resolved
Optional: check_uri has no || fail, so some failures end without a not ok line Resolved
Note: plain-text paste gets the encoded URI Still applies (unchanged production, informational)
Verified
Reproducer: combination with #12135 (current and earlier test)

Build the combination (#12135's current head 0886701 plus this PR's changes) in a fresh clone:

git clone https://github.com/omacom/omarchy && cd omarchy
git fetch origin pull/12135/head pull/13360/head
git switch --detach 0886701bed5a349e6aad2d21dceea61cc06fb6ae
git diff e1614f2bdb94f7df11eda072644b31e1e118f1ba 40a15001a1ffcefc9b751972438dcfa271b05f55 | git apply

Current test (40a1500):

bash test/shell.d/transcode-clipboard-test.sh; echo "exit $?"
ok - plain image paths keep their existing clipboard URI
ok - reserved characters are encoded rather than interpreted as URI syntax
ok - spaces are encoded in clipboard paths
ok - UTF-8 filenames produce escaped ASCII URIs
ok - newlines and tabs stay inside a single clipboard URI
ok - quotes in filenames remain data
ok - parent directory names are encoded as well
ok - relative paths and symlinks still resolve to the output file
ok - URI conversion does not import Python modules from the current directory
ok - video outputs use the same URI encoding
ok - GIF outputs preserve literal percent escapes in filenames
ok - image/png encoder failures leave the clipboard untouched
ok - video/mp4 encoder failures leave the clipboard untouched
ok - clipboard failure does not report successful completion
ok - URI conversion failure leaves the clipboard untouched
exit 0

Earlier test (f995c1c), same tree:

git show f995c1cf3481154ca1a9877e9302cb353138df56:test/shell.d/transcode-clipboard-test.sh > test/shell.d/transcode-clipboard-test.sh
bash test/shell.d/transcode-clipboard-test.sh; echo "exit $?"
not ok - successful copy reports completion
exit 1

Negative checks, same combined tree with the current test restored (git show 40a15001a1ffcefc9b751972438dcfa271b05f55:test/shell.d/transcode-clipboard-test.sh > test/shell.d/transcode-clipboard-test.sh). Move the picture branch's clipboard copy below its success notification in bin/omarchy-transcode:

python3 - <<'PY'
from pathlib import Path
p = Path('bin/omarchy-transcode')
lines = p.read_text().splitlines(keepends=True)
i = lines.index('    transcode_picture "$input" "$format" "$resolution" "$output"\n')
assert lines[i + 1] == '    copy_to_clipboard "$output"\n'
lines.insert(i + 3, lines.pop(i + 1))  # copy now runs after the success notification
p.write_text(''.join(lines))
PY

Current test: 13 ok lines, then

not ok - clipboard failure must not report success

(exit 1). With only the three negative checks changed back to the earlier ! grep -Fq 'Saved and copied to clipboard.', the same mutated tree passes all 15 checks (exit 0), because the regressed message reads Saved and copied to clipboard (<1 MB).

Environment of the recorded run: bash 5.3.15, Python 3.14.7, GNU grep 3.12, in an isolated command sandbox with a tripwire stub for every menu, clipboard, notification and encoder command (none was called). The recorded run used a tree equivalent to the commands above (tree hash checked against 0886701).


Review information

Test scope: Sandbox tests only at 40a1500, with menus, clipboard, notifications and encoders stubbed; combinations are each related PR's head plus this diff; ./test/all was not rerun and no live Wayland paste was tested.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 3, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 40a1500 against quattro, with the bug reproduced on an Omarchy worker VM. Nothing to fix.

Reproduction. On the worker I ran the real command end to end: ImageMagick made the encode, wl-copy set the live Wayland clipboard, and GIO's Gio.File.new_for_uri() read it back. On base, and on this head with the one-line fix reverted, shot#1-low.jpg resolves to shot, take?2-low.jpg to take, and lit%20pct-low.jpg to lit pct-low.jpg. On this head, all four names, including a plain one, resolve to the exact output file. The shell's clipboard history (decodeFileUri in shell/plugins/clipboard/ClipboardHistory.js) already percent-decodes, so it reads the new URIs correctly. Nothing else in the repository produces a text/uri-list.

Tests. transcode-clipboard-test.sh passes 15/15 on this head. Against base's bin/omarchy-transcode it fails at "reserved characters are encoded rather than interpreted as URI syntax". The full ./test/shell and ./test/cli suites are not green on the worker, but every failure also happens on base: four shell assertions (ascii, branding-about-animation, kernel-headers-migration, passwordless-grant-lifecycle) and the VS Code theme assertion in test/cli that #13810 fixes. This PR adds no failures.

Scope. The production change is one line and proportionate. The test is broader than the fix needs. The encoder-failure and clipboard-failure cases cover behaviour this PR doesn't change, and the quality-prompt and ffprobe stubs exist only for compatibility with #12135. That's worth keeping in mind, but it doesn't block anything.

Second opinion. Codex Medium reviewed the same diff. It found no defect in the fix and agreed the bug is real and Path.resolve().as_uri() under python3 -I is a correct fix. It also judged the test broader than necessary. Its independence from this review is not guaranteed.

Next. This is waiting on the maintainer. It isn't marked ready yet because the suite on quattro itself isn't green, and no CI has run on this head.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants