From 19a37667fa084546a2502cceb8f4bda87d1305e7 Mon Sep 17 00:00:00 2001 From: zegonix Date: Wed, 27 May 2026 18:22:18 +0200 Subject: [PATCH] (scripts) fix for spaces in paths/arguments of whitespace remover --- scripts/trailing-whitespace.sh | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/scripts/trailing-whitespace.sh b/scripts/trailing-whitespace.sh index 6daf7d7..c7a6f28 100755 --- a/scripts/trailing-whitespace.sh +++ b/scripts/trailing-whitespace.sh @@ -23,7 +23,7 @@ function remove-whitespace { unset args unset arguments - for arg in $@; do + for arg in "$@"; do if [[ "${arg}" =~ ^-[a-zA-Z]{2,}$ ]]; then temp=($(echo ${arg} | grep --color=never -o ".")) args+=(${temp[@]/#/-}) @@ -32,14 +32,14 @@ function remove-whitespace { fi done - for arg in ${args[@]}; do + for arg in "${args[@]}"; do [[ "${arg}" != "--" ]] && arguments+=("${arg}") done unset args - for arg in ${arguments[@]}; do + for arg in "${arguments[@]}"; do unset arg_found - case ${arg} in + case "${arg}" in "-u" | "--unix") arg_found="true" ffunix="true" @@ -82,18 +82,18 @@ function remove-whitespace { grep_regex=$'[[:blank:]]+\r?$' fi - for arg in ${path_args[@]}; do - files+=($( + for arg in "${path_args[@]}"; do + files+=("$( find "${arg}" \ ${exclude_paths[@]/#/-not -path } \ ${exclude_files[@]/#/-not -name } \ -type f \ -exec grep -EIq "${grep_regex}" {} \; \ -print - )) + )") done - for arg in ${file_args[@]}; do - grep -EIq "${grep_regex}" ${arg} && files+=("${arg}") + for arg in "${file_args[@]}"; do + grep -EIq "${grep_regex}" "${arg}" && files+=("${arg}") done if [[ -z "${files[@]}" ]] && [[ -n "${path_args}" ]]; then @@ -124,7 +124,7 @@ EOF fi if [[ -z "${no_action}" ]]; then - for file in ${files[@]}; do + for file in "${files[@]}"; do if [[ -n "${ffunix}" ]]; then sed -i "${sed_cmd}" ${file} else @@ -139,7 +139,7 @@ EOF tput smso echo "The following files contain whitespace:" tput sgr0 - for file in ${files[@]}; do + for file in "${files[@]}"; do echo "${file}" done elif [[ -z "${silent}" ]] && @@ -148,9 +148,8 @@ EOF tput smso echo "The following files contained whitespace:" tput sgr0 - for file in ${files[@]}; do + for file in "${files[@]}"; do echo "${file}" done fi - }