Skip to content

Commit

Permalink
Refactored link checks (#2204)
Browse files Browse the repository at this point in the history
* Refactored link checks

- Check w_download_to
- Check only URL, not whole line
- Find lines that don't start with w_download
- Allow escaped $ in URL
- Escape '\$' to '%24'
  • Loading branch information
Root-Core authored Dec 19, 2024
1 parent 418f280 commit 6ab0bc7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/linkcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ w_download() {
urlkey="$(echo "${url}" | tr / _)"
echo "${url}" > "${datadir}/${urlkey}.url"
}
# shellcheck disable=SC2317
w_download_to() {
shift
w_download "$@"
}

# Extract list of URLs from winetricks
extract_all() {
Expand All @@ -57,7 +62,11 @@ extract_all() {

# https://github.com/koalaman/shellcheck/issues/861
# shellcheck disable=SC1003
grep '^ *w_download ' "${shwinetricks}" | grep -E 'ftp|http' | grep -v "w_linkcheck_ignore=1" | sed 's/^ *//' | tr -d '\\' > url-script-fragment.tmp
grep -E '^[^#]*w_download(_to)? .*(http|ftp)s?://' "${shwinetricks}" \
| grep -vE "(w_linkcheck_ignore|WINETRICKS_SUPER_QUIET)=(TRUE|1)" \
| sed 's/^.*w_download/w_download/' \
| sed -E "s/\\$/%24/g" \
| tr -d '\\' > url-script-fragment.tmp

# shellcheck disable=SC1091
. ./url-script-fragment.tmp
Expand Down
18 changes: 16 additions & 2 deletions tests/shell-checks
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,22 @@ test_shellcheck() {
test_linkcheck() {
# Check for uses of variables in w_download when w_linkcheck_ignore isn't set
# Using w_download https://example.com/${file1} breaks src/linkcheck.sh
# FIXME: technically '$' is valid in a URL, if there's actually a URL using it this will need a tweak
if grep "^ *w_download " src/winetricks | grep -E "ftp|http" | grep -v "w_linkcheck_ignore=1" | sed "s/^ *//" | tr -d "\\\\" | grep "\\$"; then
# Escaped '$', as in '\$' are allowed

test_func() {
# No comment, only with protocol, skip flagged as ignored, remove indention
# and flags, fix double space, get n-th arg, find vars '$' and ignore '\$'.
func_name=${1}
url_arg=${2}
grep -E '^[^#]*'"${func_name}"' .*(http|ftp)s?://' "src/winetricks" \
| grep -vE "(w_linkcheck_ignore|WINETRICKS_SUPER_QUIET)=(TRUE|1)" \
| sed 's/^.*'"${func_name}"'/'"${func_name}"'/' \
| tr -s " " \
| cut -d " " -f "${url_arg}" \
| grep -E "([^\\\\\]+\\$)"
}

if ( test_func "w_download_to" 3 ) || ( test_func "w_download" 2 ); then
w_die "Do not use variables in these URLs, it breaks src/linkcheck.sh"
else
echo "linkcheck checks passed"
Expand Down

0 comments on commit 6ab0bc7

Please sign in to comment.