From f08c9d730ec054fd8f33c6e04ec728ef8ef2e352 Mon Sep 17 00:00:00 2001 From: "Alex Pooley (@zuedev)" Date: Thu, 5 Feb 2026 16:09:37 +0000 Subject: handle CRLF line endings and trailing commas in bash --- validators/bash/validate.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'validators') diff --git a/validators/bash/validate.sh b/validators/bash/validate.sh index 55324f1..a34c555 100644 --- a/validators/bash/validate.sh +++ b/validators/bash/validate.sh @@ -25,9 +25,9 @@ fi # Strip JSONC comments using sed strip_comments() { - # Remove single-line comments (// ...) and multi-line comments (/* ... */) - # This is a simplified version - doesn't handle comments inside strings perfectly - sed -e 's|//.*$||g' -e ':a;s|/\*.*\*/||g;ta' -e '/\/\*/,/\*\//d' "$1" + # Remove carriage returns (Windows line endings), single-line comments, and multi-line comments + # Also remove trailing commas before } or ] (valid in JSONC, invalid in JSON) + 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' } # Validate URI format -- cgit v1.2.3