-
-
Notifications
You must be signed in to change notification settings - Fork 0
fix(ci): the invisible-character gate never matched anything #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hyperpolymath
wants to merge
5
commits into
main
Choose a base branch
from
fix/empty-linter-pattern-never-matched
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
29f7313
fix(ci): the invisible-character gate never matched anything
hyperpolymath d29b287
fix(ci): enforce C0/NUL corruption in-step; warn on invisible Unicode
hyperpolymath 4a37a3b
fix(ci): make invisible-character PCRE locale-independent
hyperpolymath 4f11d2d
fix(ci): harden invisible-character scan
hyperpolymath 2e2fb70
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| #!/usr/bin/env bash | ||
| # SPDX-License-Identifier: MPL-2.0 | ||
| # Byte-safe scanner for invisible Unicode encodings and forbidden C0 controls. | ||
| set -u | ||
|
|
||
| scan_root="${1:-}" | ||
| results_file="${2:-}" | ||
| blocking_results_file="${3:-}" | ||
| leading_bom_results_file="${4:-}" | ||
| grep_bin="${INVISIBLE_GREP_BIN:-grep}" | ||
| find_bin="${INVISIBLE_FIND_BIN:-find}" | ||
|
|
||
| if [[ -z "$scan_root" || ! -d "$scan_root" || -z "$results_file" ]]; then | ||
| echo "usage: $0 SCAN_ROOT RESULTS_FILE [BLOCKING_RESULTS_FILE] [LEADING_BOM_RESULTS_FILE]" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| # Scan bytes under the C locale. This detects UTF-8 encodings even when another | ||
| # byte in the file is invalid UTF-8, while excluding permitted TAB/LF/CR bytes. | ||
| pattern='[\x00-\x08\x0B\x0C\x0E-\x1F]|\xC2(?:\xA0|\xAD)|\xE2\x80[\x8B-\x8F\xAA-\xAF]|\xE2\x81(?:\xA0|[\xA6-\xA9])|\xEF\xBB\xBF' | ||
| blocking_pattern='[\x00-\x08\x0B\x0C\x0E-\x1F]' | ||
| leading_bom_pattern='\A\xEF\xBB\xBF' | ||
| : > "$results_file" || exit 2 | ||
| if [[ -n "$blocking_results_file" ]]; then | ||
| : > "$blocking_results_file" || exit 2 | ||
| fi | ||
| if [[ -n "$leading_bom_results_file" ]]; then | ||
| : > "$leading_bom_results_file" || exit 2 | ||
| fi | ||
| scan_error=0 | ||
| enumeration_file="$(mktemp /tmp/rsr-invisible-files.XXXXXX)" || exit 2 | ||
| # Invoked indirectly by the EXIT trap. | ||
| # shellcheck disable=SC2329 | ||
| cleanup() { | ||
| rm -f -- "$enumeration_file" | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| if ! "$find_bin" "$scan_root" \ | ||
| -not -path '*/.git/*' -not -path '*/node_modules/*' \ | ||
| -not -path '*/.deno/*' -not -path '*/target/*' \ | ||
| -not -path '*/_build/*' -not -path '*/deps/*' \ | ||
| -not -path '*/external_corpora/*' -not -path '*/.lake/*' \ | ||
| -type f \( -name '*.rs' -o -name '*.ex' -o -name '*.exs' -o -name '*.res' \ | ||
| -o -name '*.js' -o -name '*.ts' -o -name '*.json' -o -name '*.toml' \ | ||
| -o -name '*.yml' -o -name '*.yaml' -o -name '*.md' -o -name '*.adoc' \ | ||
| -o -name '*.idr' -o -name '*.zig' -o -name '*.v' -o -name '*.jl' \ | ||
| -o -name '*.gleam' -o -name '*.hs' -o -name '*.ml' -o -name '*.sh' \) \ | ||
| -print0 > "$enumeration_file"; then | ||
| echo "file enumeration failed: $scan_root" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| while IFS= read -r -d '' filepath; do | ||
| LC_ALL=C "$grep_bin" -aPq "$pattern" "$filepath" | ||
| status=$? | ||
| case "$status" in | ||
| 0) | ||
| printf '%s\0' "$filepath" >> "$results_file" || scan_error=1 | ||
| if [[ -n "$blocking_results_file" ]]; then | ||
| LC_ALL=C "$grep_bin" -aPq "$blocking_pattern" "$filepath" | ||
| blocking_status=$? | ||
| case "$blocking_status" in | ||
| 0) printf '%s\0' "$filepath" >> "$blocking_results_file" || scan_error=1 ;; | ||
| 1) ;; | ||
| *) echo "blocking-classifier error ($blocking_status): $filepath" >&2; scan_error=1 ;; | ||
| esac | ||
| fi | ||
| if [[ -n "$leading_bom_results_file" ]]; then | ||
| LC_ALL=C "$grep_bin" -aPzoq "$leading_bom_pattern" "$filepath" | ||
| leading_bom_status=$? | ||
| case "$leading_bom_status" in | ||
| 0) printf '%s\0' "$filepath" >> "$leading_bom_results_file" || scan_error=1 ;; | ||
| 1) ;; | ||
| *) echo "leading-bom-classifier error ($leading_bom_status): $filepath" >&2; scan_error=1 ;; | ||
| esac | ||
| fi | ||
| ;; | ||
| 1) ;; | ||
| *) echo "scanner error ($status): $filepath" >&2; scan_error=1 ;; | ||
| esac | ||
| done < "$enumeration_file" | ||
|
|
||
| exit "$scan_error" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Combine the
$GITHUB_OUTPUTwrites.Lines 147-149 trigger ShellCheck SC2129 through actionlint. Group the three
echocommands and redirect the group once.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Linters/SAST tools