Skip to content
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

fix: properly handle file paths with spaces #48

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions script.sh
Original file line number Diff line number Diff line change
@@ -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)"
Expand Down Expand Up @@ -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
Expand All @@ -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;}' | awk '{printf "%s",(NR==1?"":" ")"\042"$0"\042"}END{print ""}')

echo '::group:: Running shellcheck ...'
if [ "${INPUT_REPORTER}" = 'github-pr-review' ]; then
Expand Down
2 changes: 2 additions & 0 deletions testdata/test folder/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
echo $1 # Unquoted variables
find . -name *.ogg # Unquoted find/grep patterns