From 6ab0bc785a3cde9d778cda6e5d61ab650f5aa15d Mon Sep 17 00:00:00 2001 From: Root-Core Date: Thu, 19 Dec 2024 09:40:36 +0100 Subject: [PATCH] Refactored link checks (#2204) * 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' --- src/linkcheck.sh | 11 ++++++++++- tests/shell-checks | 18 ++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/linkcheck.sh b/src/linkcheck.sh index ca7b8f48a..63e27619c 100755 --- a/src/linkcheck.sh +++ b/src/linkcheck.sh @@ -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() { @@ -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 diff --git a/tests/shell-checks b/tests/shell-checks index ac5c89520..538862f9c 100755 --- a/tests/shell-checks +++ b/tests/shell-checks @@ -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"