ALEF-PAT-019
zero-as-falsy-idguard × identifier-truthiness-conflation · severity 5 · confidence 0.85
JavaScript/TypeScript guards like `if (!id)` reject the legitimate value `0` because zero is falsy. Affects any code path where id=0 is a valid record identifier.
diagnosed in the wild
·
loading…
healed by ALEF
·
loading…
cited in posts
·
loading…
observable signature
{
"code_regex": "ifs*(s*!s*(session|user|item|product|order|account|row|message|token)?[Ii]ds*)",
"alt_regex": [
"ifs*(s*!s*w*[Ii]ds*&&",
"sessionIds*||s*w*[Ii]ds*??",
"returns*!s*[a-zA-Z]+[Ii]ds*;"
],
"applies_when": "identifier is numeric AND 0 is a valid value (e.g., row 0, message 0, system user 0)",
"does_not_apply_when": "identifier is string-typed (UUIDs, base64url, Lucia session strings, etc.) — !id correctly rejects only null/undefined/empty-string"
}verified instances (3) — from the catalog
fix archetypes
- explicit-null-checkcost: tiny
if (id == null) instead of if (!id)
- branded-id-typecost: medium
RequestId = Branded<number|string,'RequestId'> with isPresent predicate
cite as
# In a PR description / issue / RFC: fixes pattern ALEF-PAT-019 (zero-as-falsy-id) ref: https://n50.io/patterns/019 # Machine query: GET https://n50.io/api/patterns/019 # Scan your repo for this pattern: npx @alef-prime/audit-agent-system . --pattern=019