Skip to content

Commit 250c431

Browse files
committed
fix: add normalization steps when reading upstream_files.txt
1 parent fba660f commit 250c431

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

scripts/lint.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ grep -P 'lint.sh' scripts/lint.sh &>/dev/null || (
1818
exit 255
1919
)
2020

21+
# Trim leading/trailing whitespace from a single line.
22+
trim_ws() {
23+
sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'
24+
}
25+
2126
# Read excluded directories into arrays
2227
DEFAULT_FILES=()
2328
UPSTREAM_FILES=()
@@ -43,6 +48,15 @@ function read_dirs {
4348
local -a upstream_find_args=()
4449
local -a upstream_exclude_args=()
4550
for line in "${upstream_folders[@]}"; do
51+
# Normalize and skip invalid entries to avoid matching the entire repo:
52+
# - strip CR (handles CRLF files)
53+
# - trim leading/trailing whitespace
54+
# - skip blank lines and comment lines
55+
line=${line%$'\r'}
56+
line=$(printf '%s' "$line" | trim_ws)
57+
[[ -z "$line" ]] && continue
58+
[[ "${line:0:1}" == "#" ]] && continue
59+
4660
if [[ "$line" == !* ]]; then
4761
# Excluding files with !
4862
upstream_exclude_args+=(! -path "./${line:1}")
@@ -51,7 +65,9 @@ function read_dirs {
5165
fi
5266
done
5367
# Remove the last '-o' from the arrays
54-
unset 'upstream_find_args[${#upstream_find_args[@]}-1]'
68+
if ((${#upstream_find_args[@]} > 0)); then
69+
unset 'upstream_find_args[${#upstream_find_args[@]}-1]'
70+
fi
5571

5672
# Find upstream files
5773
mapfile -t UPSTREAM_FILES < <(

0 commit comments

Comments
 (0)