Skip to content

Commit 8ecd4cb

Browse files
fix(ci): the invisible-character gate never matched anything (#165)
**Measured 2026-08-27: this gate caught 0 of 6 invisible-character test cases.** It has never detected an NBSP, zero-width space, BOM, soft hyphen, bidi override or word joiner. ## Root cause The pattern used UTF-8 **byte sequences** (`\xc2\xa0`) while `grep -P` matches **characters**. Bytes `c2 a0` are *one* character U+00A0; `\xc2\xa0` asks for *two*, U+00C2 then U+00A0 — never present. ``` grep -P '\xc2\xa0' -> miss grep -P '\x{a0}' -> MATCH ``` Only `\x00` worked, being single-byte in both readings. The gate ran, passed, and could not see what it exists to see. ## Fixed - **codepoint escapes** in place of byte sequences - **C0 controls** `\x01-\x08,\x0B,\x0C,\x0E-\x1F` added (TAB/LF/CR excluded) - **`grep -a`** — without it grep skips any NUL-bearing file as binary The C0 range matters: a stray **backspace byte** made a workflow unparseable in `developer-ecosystem`, so it never ran — and this linter called it clean. Canonical fix: hyperpolymath/empty-linter#70. **1 file(s)** here. **Verified:** YAML re-parsed, and the corrected pattern was confirmed to catch a real NBSP before the change was kept. --------- Signed-off-by: Jonathan D.A. Jewell <6759885+hyperpolymath@users.noreply.github.com> Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com>
1 parent 9dfe403 commit 8ecd4cb

5 files changed

Lines changed: 97 additions & 31 deletions

File tree

‎.github/workflows/dogfood-gate.yml‎

Lines changed: 94 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -124,42 +124,109 @@ jobs:
124124
# Inline invisible character detection (from empty-linter's core patterns).
125125
# Checks for: zero-width spaces, zero-width joiners, BOM, soft hyphens,
126126
# non-breaking spaces, null bytes, and other invisible Unicode in source files.
127-
set +e
128-
PATTERNS='\xc2\xa0|\xe2\x80\x8b|\xe2\x80\x8c|\xe2\x80\x8d|\xef\xbb\xbf|\xc2\xad|\xe2\x80\x8e|\xe2\x80\x8f|\xe2\x80\xaa|\xe2\x80\xab|\xe2\x80\xac|\xe2\x80\xad|\xe2\x80\xae|\x00'
129-
find "$GITHUB_WORKSPACE" \
130-
-not -path '*/.git/*' -not -path '*/node_modules/*' \
131-
-not -path '*/.deno/*' -not -path '*/target/*' \
132-
-not -path '*/_build/*' -not -path '*/deps/*' \
133-
-not -path '*/external_corpora/*' -not -path '*/.lake/*' \
134-
-type f \( -name '*.rs' -o -name '*.ex' -o -name '*.exs' -o -name '*.res' \
135-
-o -name '*.js' -o -name '*.ts' -o -name '*.json' -o -name '*.toml' \
136-
-o -name '*.yml' -o -name '*.yaml' -o -name '*.md' -o -name '*.adoc' \
137-
-o -name '*.idr' -o -name '*.zig' -o -name '*.v' -o -name '*.jl' \
138-
-o -name '*.gleam' -o -name '*.hs' -o -name '*.ml' -o -name '*.sh' \) \
139-
-exec grep -Prl "$PATTERNS" {} \; > /tmp/empty-lint-results.txt 2>/dev/null
140-
EL_EXIT=$?
141-
set -e
142-
143-
FINDINGS=$(wc -l < /tmp/empty-lint-results.txt 2>/dev/null || echo 0)
144-
echo "findings=$FINDINGS" >> "$GITHUB_OUTPUT"
145-
echo "exit_code=$EL_EXIT" >> "$GITHUB_OUTPUT"
146-
echo "ready=true" >> "$GITHUB_OUTPUT"
147-
148-
# Emit annotations for each file with invisible chars
149-
while IFS= read -r filepath; do
150-
[ -z "$filepath" ] && continue
151-
REL_PATH="${filepath#$GITHUB_WORKSPACE/}"
152-
echo "::warning file=${REL_PATH}::Invisible Unicode characters detected (zero-width space, BOM, NBSP, etc.)"
153-
done < /tmp/empty-lint-results.txt
127+
python3 - <<'PY'
128+
import os
129+
from pathlib import Path
130+
131+
root = Path(os.environ["GITHUB_WORKSPACE"])
132+
skipped_dirs = {
133+
".cache", ".deno", ".elixir_ls", ".git", ".lake", ".zig-cache",
134+
"_build", "build", "coverage", "deps", "dist", "external_corpora",
135+
"node_modules", "out", "target", "vendor", "zig-cache", "zig-out",
136+
}
137+
intentional_fixture_dirs = {
138+
("tests", "fixtures", "bom-detection"),
139+
("tests", "fixtures", "empty-linter"),
140+
}
141+
source_suffixes = {
142+
".adoc", ".adb", ".ads", ".agda", ".c", ".cc", ".clj", ".cljs",
143+
".cpp", ".erl", ".ex", ".exs", ".fs", ".fsi", ".fsx", ".gleam",
144+
".h", ".hh", ".hpp", ".hrl", ".hs", ".idr", ".java", ".jl",
145+
".js", ".json", ".kt", ".kts", ".lean", ".lua", ".md", ".ml",
146+
".php", ".r", ".rb", ".res", ".rs", ".scala", ".sh", ".swift",
147+
".toml", ".ts", ".v", ".yaml", ".yml", ".zig",
148+
}
149+
invisible_codepoints = {
150+
0x00A0, 0x00AD, 0x2060, 0xFEFF,
151+
*range(0x200B, 0x2010),
152+
*range(0x202A, 0x2030),
153+
*range(0x2066, 0x206A),
154+
}
155+
156+
def command_escape(value):
157+
return str(value).replace("%", "%25").replace("\r", "%0D").replace("\n", "%0A")
158+
159+
def property_escape(value):
160+
return command_escape(value).replace(":", "%3A").replace(",", "%2C")
161+
162+
# Runtime regression for GitHub workflow-command property delimiters.
163+
assert property_escape("docs/a,b::c.md") == "docs/a%2Cb%3A%3Ac.md"
164+
165+
def intentionally_invalid_fixture(relative):
166+
return any(relative.parts[:len(prefix)] == prefix for prefix in intentional_fixture_dirs)
167+
168+
findings = []
169+
errors = []
170+
for directory, dirnames, filenames in os.walk(root, topdown=True):
171+
dirnames[:] = [name for name in dirnames if name not in skipped_dirs]
172+
directory_path = Path(directory)
173+
for filename in filenames:
174+
path = directory_path / filename
175+
relative = path.relative_to(root)
176+
if (
177+
path.is_symlink()
178+
or path.suffix.lower() not in source_suffixes
179+
or intentionally_invalid_fixture(relative)
180+
):
181+
continue
182+
try:
183+
data = path.read_bytes()
184+
except OSError as error:
185+
errors.append((relative, f"could not read file: {error}"))
186+
continue
187+
188+
reasons = set()
189+
if data.startswith(b"\xef\xbb\xbf"):
190+
reasons.add("leading UTF-8 BOM")
191+
if any(byte <= 0x08 or byte in (0x0B, 0x0C) or 0x0E <= byte <= 0x1F for byte in data):
192+
reasons.add("C0 control character")
193+
try:
194+
text_content = data.decode("utf-8", errors="strict")
195+
except UnicodeDecodeError as error:
196+
errors.append((relative, f"invalid UTF-8 at byte {error.start}"))
197+
continue
198+
if any(ord(character) in invisible_codepoints for character in text_content):
199+
reasons.add("invisible Unicode code point")
200+
if reasons:
201+
findings.append((relative, ", ".join(sorted(reasons))))
202+
203+
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as output:
204+
output.write(f"findings={len(findings)}\n")
205+
output.write(f"exit_code={2 if errors else 0}\n")
206+
output.write("ready=true\n")
207+
208+
for relative, reasons in findings:
209+
print(f"::warning file={property_escape(relative)}::Invisible characters detected: {command_escape(reasons)}")
210+
for relative, reason in errors:
211+
print(f"::error file={property_escape(relative)}::Invisible-character scan failed: {command_escape(reason)}")
212+
PY
154213
155214
- name: Write summary
156215
run: |
157216
if [ "${{ steps.lint.outputs.ready }}" = "true" ]; then
158217
FINDINGS="${{ steps.lint.outputs.findings }}"
218+
EXIT_CODE="${{ steps.lint.outputs.exit_code }}"
219+
if [ "$EXIT_CODE" -ne 0 ] 2>/dev/null; then
220+
echo "## Empty-Linter Results" >> "$GITHUB_STEP_SUMMARY"
221+
echo "" >> "$GITHUB_STEP_SUMMARY"
222+
echo ":x: Scanner execution failed; see error annotations above." >> "$GITHUB_STEP_SUMMARY"
223+
exit 1
224+
fi
159225
if [ "$FINDINGS" -gt 0 ] 2>/dev/null; then
160226
echo "## Empty-Linter Results" >> "$GITHUB_STEP_SUMMARY"
161227
echo "" >> "$GITHUB_STEP_SUMMARY"
162228
echo "Found **${FINDINGS}** invisible character issue(s). See annotations above." >> "$GITHUB_STEP_SUMMARY"
229+
exit 1
163230
else
164231
echo "## Empty-Linter Results" >> "$GITHUB_STEP_SUMMARY"
165232
echo "" >> "$GITHUB_STEP_SUMMARY"

‎.github/workflows/governance.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ permissions:
1616

1717
jobs:
1818
governance:
19-
uses: hyperpolymath/standards/.github/workflows/governance-reusable.yml@84355587cb2a1f86e6882de83514a32db2646e7a
19+
uses: hyperpolymath/standards/.github/workflows/governance-reusable.yml@6b38eb50104901e2fec80f9455a972bc3eced813

‎aletheia/.github/workflows/governance.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ permissions:
2424
jobs:
2525
governance:
2626
uses: hyperpolymath/standards/.github/workflows/governance-reusable.yml@861b5e911d9e5dcfb3c0ab3dd2a9a3c8fd0a1613
27-
timeout-minutes: 10

‎docs/proof-debt.adoc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ the canonical `+hyperpolymath/absolute-zero+` repo upstream and bump the
221221
submodule pin here (`+git submodule update --remote absolute-zero+` then
222222
commit).
223223
. If a *new* proof-bearing file appears *outside* `+absolute-zero/+`
224-
(e.g. under `+aletheia/+` for the Rust verification pipeline, or under
224+
(e.g. under `+aletheia/+` for the Rust verification pipeline, or under
225225
`+contractiles/+`), classify it into §(a)/(b)/(c)/(d) per the canonical
226226
schema. That would be load-bearing maa-framework debt.
227227

‎docs/tech-debt-2026-05-26.adoc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ soundness-relevant escape hatches in Haskell/Rust source.
3030

3131
*Recommended next move:* triage each finding into one of: (a) discharge
3232
by proof, (b) cover with property-tests + a documented refutation
33-
budget, or (c) annotate as a known/necessary axiom (e.g. `+funExt+`) in
33+
budget, or (c) annotate as a known/necessary axiom (e.g. `+funExt+`) in
3434
`+docs/proof-debt.md+`.
3535

3636
=== 2. Licence debt

0 commit comments

Comments
 (0)