Merge pull request #8416 from mdisec/theme-name-shell-syntax
Refuse a theme name that is shell syntax, and quote the one the unlock picker returns
(cherry picked from commit 9da8824098)
This commit is contained in:
5 files changed
+196
-7
No files matched your search
@@ -92,6 +92,83 @@ done
|
||||
|
||||
pass "a URL whose name would climb out of the themes directory never reaches git"
|
||||
|
||||
# The derived name outlives the clone: it is the theme's directory name, and
|
||||
# Style > Unlock builds a command line out of the name the picker returned. A
|
||||
# repo whose name carries shell syntax would hand that picker its own command,
|
||||
# so the name is refused here rather than quoted at each place it lands.
|
||||
for url in \
|
||||
"https://example.com/omarchy-a';id;'b-theme.git" \
|
||||
'https://example.com/a$(id).git' \
|
||||
'https://example.com/a`id`.git' \
|
||||
"https://example.com/a b.git" \
|
||||
"https://example.com/-a.git"; do
|
||||
if install_theme "$url"; then
|
||||
fail "omarchy-theme-install refuses the derived name from '$url'"
|
||||
fi
|
||||
|
||||
[[ ! -s $git_calls ]] || fail "omarchy-theme-install refuses '$url' before running git" "$(cat "$git_calls")"
|
||||
done
|
||||
|
||||
pass "a URL whose name would be shell syntax never reaches git"
|
||||
|
||||
# And the check is an allowlist, so the punctuation a real theme name uses has
|
||||
# to keep working.
|
||||
install_theme "https://github.com/example/omarchy-tokyo_night.2-theme.git" ||
|
||||
fail "omarchy-theme-install accepts the punctuation a theme name uses"
|
||||
grep -Fq "/themes/tokyo_night.2" "$git_calls" ||
|
||||
fail "omarchy-theme-install derives a name carrying an underscore and a dot" "$(cat "$git_calls")"
|
||||
|
||||
pass "a theme name may still hold an underscore, a dot, and a dash"
|
||||
|
||||
# A plus is neither path-climb nor shell syntax, and a leading underscore is
|
||||
# neither the `..` climb nor the dash that reads as an option, so the allowlist
|
||||
# keeps both rather than stranding a repo that names itself with them.
|
||||
install_theme "https://github.com/example/omarchy-c++-theme.git" ||
|
||||
fail "omarchy-theme-install accepts a name holding a plus"
|
||||
grep -Fq "/themes/c++" "$git_calls" ||
|
||||
fail "omarchy-theme-install derives a name carrying a plus" "$(cat "$git_calls")"
|
||||
|
||||
install_theme "https://github.com/example/_private.git" ||
|
||||
fail "omarchy-theme-install accepts a name starting with an underscore"
|
||||
grep -Fq "/themes/_private" "$git_calls" ||
|
||||
fail "omarchy-theme-install derives a name starting with an underscore" "$(cat "$git_calls")"
|
||||
|
||||
pass "a plus and a leading underscore are still usable theme names"
|
||||
|
||||
# git reads a colon before any slash as the scp-style separator, so the path
|
||||
# after it does not have to hold one. Without that reading, the whole URL becomes
|
||||
# the theme name and the allowlist above refuses a repo that clones fine.
|
||||
install_theme "git@example.com:omarchy-blue-theme.git" ||
|
||||
fail "omarchy-theme-install accepts a home-relative scp-style URL"
|
||||
grep -Fq "/themes/blue" "$git_calls" ||
|
||||
fail "omarchy-theme-install names the theme after the repo, not the whole URL" "$(cat "$git_calls")"
|
||||
|
||||
# A colon that is part of a local path, not an scp separator, keeps its prefix.
|
||||
install_theme "/srv/git:mirrors/omarchy-blue-theme.git" ||
|
||||
fail "omarchy-theme-install accepts a local path holding a colon"
|
||||
grep -Fq "/themes/blue" "$git_calls" ||
|
||||
fail "omarchy-theme-install reads a colon after a slash as part of the path" "$(cat "$git_calls")"
|
||||
|
||||
pass "an scp-style URL with no slash after the colon still names the theme"
|
||||
|
||||
# The allowlist is a bracket range, and a range follows the locale's collation
|
||||
# rather than ASCII: under en_US.UTF-8 an unpinned `[a-z]` takes in `é`, so the
|
||||
# same URL would install on one desktop and be refused on the next.
|
||||
if locale -a 2>/dev/null | grep -qix 'en_US.utf-\?8'; then
|
||||
for locale_name in C en_US.UTF-8; do
|
||||
if LC_ALL=$locale_name install_theme "https://github.com/example/omarchy-café-theme.git"; then
|
||||
fail "omarchy-theme-install refuses a non-ASCII theme name under LC_ALL=$locale_name" "$(cat "$git_calls")"
|
||||
fi
|
||||
|
||||
[[ ! -s $git_calls ]] ||
|
||||
fail "omarchy-theme-install refuses a non-ASCII name before running git" "$(cat "$git_calls")"
|
||||
done
|
||||
|
||||
pass "the accepted set does not move with the desktop's locale"
|
||||
else
|
||||
pass "no en_US.UTF-8 locale; skipping the locale-pinning check"
|
||||
fi
|
||||
|
||||
# basename reads a leading dash as an option once the scp-style prefix is gone.
|
||||
install_theme "host:-s/foo.git" || fail "omarchy-theme-install accepts a normal scp-style URL"
|
||||
grep -Fq -- "-- host:-s/foo.git" "$git_calls" || fail "omarchy-theme-install passes the URL after --" "$(cat "$git_calls")"
|
||||
|
||||
Reference in new issue
Block a user