From bbdf8cc8d43c6d2b2150ec0687ce16a36fbe56f7 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 26 Jan 2023 21:45:36 -0700 Subject: [PATCH 1/8] fix: properly handle file paths with spaces --- testdata/test folder/test.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 testdata/test folder/test.sh diff --git a/testdata/test folder/test.sh b/testdata/test folder/test.sh new file mode 100644 index 0000000..d520aae --- /dev/null +++ b/testdata/test folder/test.sh @@ -0,0 +1,2 @@ +echo $1 # Unquoted variables +find . -name *.ogg # Unquoted find/grep patterns From d5b94480a2a117e4db95c4e01f602bca70ea4995 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 26 Jan 2023 21:50:21 -0700 Subject: [PATCH 2/8] Update script.sh --- script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.sh b/script.sh index 86432a9..c78b54c 100755 --- a/script.sh +++ b/script.sh @@ -48,7 +48,7 @@ while read -r pattern; do done <<< "${INPUT_EXCLUDE:-}" # Match all files matching the pattern -files_with_pattern=$(find "${paths[@]}" "${excludes[@]}" -type f "${names[@]}") +files_with_pattern=$(find "${paths[@]}" "${excludes[@]}" -type f "${names[@]}" -print0 | xargs -0) # Match all files with a shebang (e.g. "#!/usr/bin/env zsh" or even "#!bash") in the first line of a file # Ignore files which match "$pattern" in order to avoid duplicates From 66b6d9c93b33777cdcdfb8cd73670dd85d11c6e9 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 26 Jan 2023 21:59:31 -0700 Subject: [PATCH 3/8] Update script.sh --- script.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/script.sh b/script.sh index c78b54c..932886a 100755 --- a/script.sh +++ b/script.sh @@ -31,24 +31,24 @@ export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" paths=() while read -r pattern; do - [[ -n ${pattern} ]] && paths+=("${pattern}") + [[ -n ${pattern} ]] && paths+=("\"${pattern}\"") done <<< "${INPUT_PATH:-.}" names=() if [[ "${INPUT_PATTERN:-*}" != '*' ]]; then while read -r pattern; do - [[ -n ${pattern} ]] && names+=(-o -name "${pattern}") + [[ -n ${pattern} ]] && names+=(-o -name "\"${pattern}\"") done <<< "${INPUT_PATTERN}" (( ${#names[@]} )) && { names[0]='('; names+=(')'); } fi excludes=() while read -r pattern; do - [[ -n ${pattern} ]] && excludes+=(-not -path "${pattern}") + [[ -n ${pattern} ]] && excludes+=(-not -path "\"${pattern}\"") done <<< "${INPUT_EXCLUDE:-}" # Match all files matching the pattern -files_with_pattern=$(find "${paths[@]}" "${excludes[@]}" -type f "${names[@]}" -print0 | xargs -0) +files_with_pattern=$(find "${paths[@]}" "${excludes[@]}" -type f "${names[@]}") # Match all files with a shebang (e.g. "#!/usr/bin/env zsh" or even "#!bash") in the first line of a file # Ignore files which match "$pattern" in order to avoid duplicates From 3d8f1195da078d22bbc7cc08921e57a1f1d43482 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 26 Jan 2023 22:24:44 -0700 Subject: [PATCH 4/8] Update script.sh --- script.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/script.sh b/script.sh index 932886a..86432a9 100755 --- a/script.sh +++ b/script.sh @@ -31,20 +31,20 @@ export REVIEWDOG_GITHUB_API_TOKEN="${INPUT_GITHUB_TOKEN}" paths=() while read -r pattern; do - [[ -n ${pattern} ]] && paths+=("\"${pattern}\"") + [[ -n ${pattern} ]] && paths+=("${pattern}") done <<< "${INPUT_PATH:-.}" names=() if [[ "${INPUT_PATTERN:-*}" != '*' ]]; then while read -r pattern; do - [[ -n ${pattern} ]] && names+=(-o -name "\"${pattern}\"") + [[ -n ${pattern} ]] && names+=(-o -name "${pattern}") done <<< "${INPUT_PATTERN}" (( ${#names[@]} )) && { names[0]='('; names+=(')'); } fi excludes=() while read -r pattern; do - [[ -n ${pattern} ]] && excludes+=(-not -path "\"${pattern}\"") + [[ -n ${pattern} ]] && excludes+=(-not -path "${pattern}") done <<< "${INPUT_EXCLUDE:-}" # Match all files matching the pattern From da5d4a81a4172cb830ebf74329898813daca56e6 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 26 Jan 2023 22:27:30 -0700 Subject: [PATCH 5/8] Update script.sh --- script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.sh b/script.sh index 86432a9..9120239 100755 --- a/script.sh +++ b/script.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -u +set -ux echo '::group:: Installing shellcheck ... https://github.com/koalaman/shellcheck' TEMP_PATH="$(mktemp -d)" From 3ada1096dd148e0efc1a7662d1979fa2b8b9974f Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 26 Jan 2023 22:37:25 -0700 Subject: [PATCH 6/8] Update script.sh --- script.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/script.sh b/script.sh index 9120239..cc02ddc 100755 --- a/script.sh +++ b/script.sh @@ -48,12 +48,12 @@ while read -r pattern; do done <<< "${INPUT_EXCLUDE:-}" # Match all files matching the pattern -files_with_pattern=$(find "${paths[@]}" "${excludes[@]}" -type f "${names[@]}") +files_with_pattern=$(find "${paths[@]}" "${excludes[@]}" -type f "${names[@]}" | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') # Match all files with a shebang (e.g. "#!/usr/bin/env zsh" or even "#!bash") in the first line of a file # Ignore files which match "$pattern" in order to avoid duplicates if [ "${INPUT_CHECK_ALL_FILES_WITH_SHEBANGS}" = "true" ]; then - files_with_shebang=$(find "${paths[@]}" "${excludes[@]}" -not "${names[@]}" -type f -print0 | xargs -0 awk 'FNR==1 && /^#!.*sh/ { print FILENAME }') + files_with_shebang=$(find "${paths[@]}" "${excludes[@]}" -not "${names[@]}" -type f -print0 | xargs -0 awk 'FNR==1 && /^#!.*sh/ { print FILENAME }' | awk -v d="|" '{s=(NR==1?s:s d)$0}END{print s}') fi # Exit early if no files have been found @@ -62,7 +62,7 @@ if [ -z "${files_with_pattern}" ] && [ -z "${files_with_shebang:-}" ]; then exit 0 fi -FILES="${files_with_pattern} ${files_with_shebang:-}" +FILES=$(echo "${files_with_pattern} ${files_with_shebang:-}" | awk '{gsub(/\|/,"\n"); print $0;}') echo '::group:: Running shellcheck ...' if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then From 5c7a55a055a3519af5fe6d68abbfc075d84fff79 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 26 Jan 2023 22:48:37 -0700 Subject: [PATCH 7/8] Update script.sh --- script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.sh b/script.sh index cc02ddc..9c3a2c6 100755 --- a/script.sh +++ b/script.sh @@ -62,7 +62,7 @@ if [ -z "${files_with_pattern}" ] && [ -z "${files_with_shebang:-}" ]; then exit 0 fi -FILES=$(echo "${files_with_pattern} ${files_with_shebang:-}" | awk '{gsub(/\|/,"\n"); print $0;}') +FILES=$(echo "${files_with_pattern} ${files_with_shebang:-}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk '{printf ""%s" ", $1}') echo '::group:: Running shellcheck ...' if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then From 0138c2f38b8e4d131097fbe7e4b8556d48906882 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Thu, 26 Jan 2023 23:05:57 -0700 Subject: [PATCH 8/8] Update script.sh --- script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.sh b/script.sh index 9c3a2c6..bb00791 100755 --- a/script.sh +++ b/script.sh @@ -62,7 +62,7 @@ if [ -z "${files_with_pattern}" ] && [ -z "${files_with_shebang:-}" ]; then exit 0 fi -FILES=$(echo "${files_with_pattern} ${files_with_shebang:-}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk '{printf ""%s" ", $1}') +FILES=$(echo "${files_with_pattern} ${files_with_shebang:-}" | awk '{gsub(/\|/,"\n"); print $0;}' | awk '{printf "%s",(NR==1?"":" ")"\042"$0"\042"}END{print ""}') echo '::group:: Running shellcheck ...' if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then