Repository navigation
games-retro-install: spec-correct .desktop escaping for ROM names and paths #13935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 2 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
04733ba
[muse] games-retro-install: escape .desktop Exec quoting, string valu…
78456d1
[muse] games-retro-install: fix false-passing newline test, escape ne…
71fc24a
games-retro-install: string-escape the whole Exec line, and key the f…
omarchybot 6859dae
games-retro-install test: launch the entry through GLib and check ret…
omarchybot b71e511
Fix RetroArch launcher identity for relative paths
kvnloo 7d3848f
Test duplicate RetroArch installs across path forms
kvnloo 296ea7d
fix(games): preserve terminal newlines in canonical ROM path
kvnloo b9f9d44
test(games): cover terminal-newline ROMs and relative install failure
kvnloo c295689
test(games): repair newline coverage and require relative install suc…
kvnloo 06bff2c
test(games): preserve bash ANSI-C newline fixture in ROM roundtrip
kvnloo f7684b0
test(games): require relative install to recreate canonical launcher
kvnloo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #!/bin/bash | ||
|
|
||
| # games-retro-install must emit .desktop files whose Exec quoting and Name | ||
| # values survive adversarial ROM filenames (quotes, %, newlines, names that | ||
| # clean to nothing). | ||
|
|
||
| source "$(dirname "$0")/base-test.sh" | ||
|
|
||
| workdir=$(mktemp -d) | ||
| trap 'rm -rf "$workdir"' EXIT | ||
|
|
||
| mkdir -p "$workdir/stubs" "$workdir/cores" "$workdir/roms" "$workdir/home" | ||
| touch "$workdir/cores/snes9x_libretro.so" | ||
|
|
||
| for stub in update-desktop-database omarchy-notification-send; do | ||
| printf '#!/bin/bash\nexit 0\n' >"$workdir/stubs/$stub" | ||
| done | ||
| chmod +x "$workdir/stubs"/* | ||
|
|
||
| install_game() { | ||
| HOME="$workdir/home" PATH="$workdir/stubs:/usr/bin:/bin" \ | ||
| bash "$ROOT/bin/omarchy-games-retro-install" "$workdir/cores/snes9x_libretro.so" "$1" | ||
| } | ||
|
|
||
| apps="$workdir/home/.local/share/applications" | ||
|
|
||
| # 1. A quote in the ROM path must not break the Exec argument grouping. | ||
| touch "$workdir/roms/My \"Best\" Game.sfc" | ||
| install_game "$workdir/roms/My \"Best\" Game.sfc" | ||
| exec_line=$(grep '^Exec=' "$apps/my-best-game.desktop") | ||
| [[ $exec_line == *'My \"Best\" Game.sfc"' ]] || fail "quote in ROM path is escaped in Exec" "$exec_line" | ||
| pass "quote in ROM path is escaped in Exec" | ||
|
greptile-apps[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| # 2. A literal % must be doubled so the launcher does not treat it as a field code. | ||
| touch "$workdir/roms/100% Complete.sfc" | ||
| install_game "$workdir/roms/100% Complete.sfc" | ||
| exec_line=$(grep '^Exec=' "$apps/100-complete.desktop") | ||
| [[ $exec_line == *'100%% Complete.sfc"' ]] || fail "% in ROM path is doubled in Exec" "$exec_line" | ||
| pass "% in ROM path is doubled in Exec" | ||
|
|
||
| touch "$workdir/roms/game%U.sfc" | ||
| install_game "$workdir/roms/game%U.sfc" | ||
| exec_line=$(grep '^Exec=' "$apps/game-u.desktop") | ||
| [[ $exec_line == *'game%%U.sfc"' ]] || fail "%U in ROM path is doubled in Exec" "$exec_line" | ||
| pass "%U in ROM path is doubled in Exec" | ||
|
|
||
| # 3. A newline in the filename must not inject a second key line. The | ||
| # generated entry is identified by its exact slug-derived filename, never by | ||
| # "first file in the directory": $apps still holds the entries from cases | ||
| # 1-2, and head -1 would inspect an unrelated clean file. | ||
| rm -f "$apps"/*.desktop | ||
| newline_rom=$'roms/evil\nExec=touch-pwned.sfc' | ||
| touch "$workdir/$newline_rom" | ||
| install_game "$workdir/$newline_rom" | ||
| desktop_files=("$apps"/*.desktop) | ||
| (( ${#desktop_files[@]} == 1 )) || fail "newline ROM produces exactly one .desktop entry" "$(ls "$apps")" | ||
| desktop_file="${desktop_files[0]}" | ||
| [[ $desktop_file == */evil-exec-touch-pwned.desktop ]] || fail "newline ROM lands in the slug-derived entry" "$desktop_file" | ||
| line_count=$(wc -l <"$desktop_file") | ||
| (( line_count == 10 )) || fail "newline in filename cannot inject .desktop key lines (got $line_count lines)" | ||
| grep -q '^Exec=touch-pwned$' "$desktop_file" && fail "injected Exec= key line is absent" | ||
| grep -q 'evil\\nExec=touch-pwned' "$desktop_file" || fail "newline in the Exec argument is escaped, not raw" | ||
| pass "newline in filename cannot inject .desktop key lines" | ||
|
|
||
| # 4. A name that cleans to nothing still gets a real entry, not ".desktop". | ||
| rm -f "$apps"/*.desktop | ||
| touch "$workdir/roms/(Europe).sfc" | ||
| install_game "$workdir/roms/(Europe).sfc" | ||
| [[ ! -e $apps/.desktop ]] || fail "(Europe).sfc must not land in .desktop" | ||
| desktop_count=$(ls "$apps"/*.desktop | wc -l) | ||
| (( desktop_count == 1 )) || fail "(Europe).sfc produces exactly one .desktop entry" "$(ls "$apps")" | ||
| name_line=$(grep '^Name=' "$apps"/*.desktop) | ||
| [[ -n ${name_line#Name=} ]] || fail "(Europe).sfc gets a non-empty Name" | ||
| pass "(Europe).sfc gets a real entry with a non-empty Name" | ||
|
|
||
| # 5. Ordinary names are byte-identical to the old output shape. | ||
| rm -f "$apps"/*.desktop | ||
| touch "$workdir/roms/Super Game (USA).sfc" | ||
| install_game "$workdir/roms/Super Game (USA).sfc" | ||
| grep -qxF "Exec=retroarch -L \"$workdir/cores/snes9x_libretro.so\" \"$workdir/roms/Super Game (USA).sfc\"" "$apps/super-game.desktop" \ | ||
| || fail "ordinary ROM keeps the plain Exec shape" | ||
| grep -qxF 'Name=Super Game' "$apps/super-game.desktop" || fail "ordinary ROM keeps the plain Name shape" | ||
| pass "ordinary ROM keeps the plain .desktop shape" | ||
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.
Uh oh!
There was an error while loading. Please reload this page.