Skip to content

Commit f08c9d7

Browse files
committed
handle CRLF line endings and trailing commas in bash
1 parent d2fb93d commit f08c9d7

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

validators/bash/validate.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ fi
2525

2626
# Strip JSONC comments using sed
2727
strip_comments() {
28-
# Remove single-line comments (// ...) and multi-line comments (/* ... */)
29-
# This is a simplified version - doesn't handle comments inside strings perfectly
30-
sed -e 's|//.*$||g' -e ':a;s|/\*.*\*/||g;ta' -e '/\/\*/,/\*\//d' "$1"
28+
# Remove carriage returns (Windows line endings), single-line comments, and multi-line comments
29+
# Also remove trailing commas before } or ] (valid in JSONC, invalid in JSON)
30+
cat "$1" | tr -d '\r' | sed -e 's|//.*$||g' -e ':a;s|/\*.*\*/||g;ta' -e '/\/\*/,/\*\//d' | sed -e 's/,\s*}/}/g' -e 's/,\s*]/]/g'
3131
}
3232

3333
# Validate URI format

0 commit comments

Comments
 (0)