diff options
| -rw-r--r-- | .github/workflows/test-validators.yml | 6 | ||||
| -rw-r--r-- | validators/bash/validate.sh | 10 |
2 files changed, 11 insertions, 5 deletions
diff --git a/.github/workflows/test-validators.yml b/.github/workflows/test-validators.yml index dae7308..f734b5a 100644 --- a/.github/workflows/test-validators.yml +++ b/.github/workflows/test-validators.yml @@ -86,21 +86,25 @@ jobs: - uses: actions/checkout@v4 - name: Install dependencies - run: apk add --no-cache bash jq coreutils + run: apk add --no-cache bash jq coreutils sed - name: Make script executable run: chmod +x validators/bash/validate.sh - name: Validate minimal example + shell: bash run: ./validators/bash/validate.sh examples/minimal.gitinfo - name: Validate open-source-project example + shell: bash run: ./validators/bash/validate.sh examples/open-source-project.gitinfo - name: Validate mirror-only example (JSONC with comments) + shell: bash run: ./validators/bash/validate.sh examples/mirror-only.gitinfo - name: Test invalid file detection + shell: bash run: | echo '{"invalid_field": "should fail"}' > /tmp/invalid.gitinfo if ./validators/bash/validate.sh /tmp/invalid.gitinfo; then diff --git a/validators/bash/validate.sh b/validators/bash/validate.sh index 82b4af2..201c0b7 100644 --- a/validators/bash/validate.sh +++ b/validators/bash/validate.sh @@ -25,10 +25,12 @@ fi # Strip JSONC comments using sed strip_comments() { - # 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) - # Uses POSIX-compatible sed syntax for portability (works with busybox sed) - cat "$1" | tr -d '\r' | sed 's|//.*$||g' | sed 's|/\*[^*]*\*/||g' | sed 's/,[ ]*}/}/g' | sed 's/,[ ]*]/]/g' + # Remove carriage returns, single-line comments, multi-line comments, and trailing commas + tr -d '\r' < "$1" \ + | sed 's|//.*||g' \ + | sed 's|/\*[^*]*\*/||g' \ + | sed 's/,[[:space:]]*}/}/g' \ + | sed 's/,[[:space:]]*]/]/g' } # Validate URI format |
