FAILURE MAP
← Case archive

FA-48116 / Delimited text / Open access

Formula screening ignores leading whitespace · case 01

A structured table violates the declared record or column contract.

Verified by executionVariant 1 · 9 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Formula screening ignores leading whitespace.

VERIFIED REPAIR

Preserve the named invariant at the faulty decision: probe = cell.lstrip(' \t')

Unsuccessful approach: The alternate implementation still violates the same declared invariant: formula screening ignores leading whitespace.

Case contract

Encode already textual comma cells for a spreadsheet-facing export. Prefix a single apostrophe if the first non-space/non-tab character is =,+,-, or @. An existing leading apostrophe is preserved without duplication. Then double embedded quotes and quote every cell. Return LF-terminated row. This is a stipulated conservative transport policy, not a universal spreadsheet security guarantee.

Why this case matters

Delimited interchange needs explicit framing, schema and field semantics at ingestion and emission boundaries.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
def _vary(value):
    if value == '@END': return 3 + 4*N
    if isinstance(value, str): return value.replace('@', 'cell' * N)
    if isinstance(value, list): return [_vary(x) for x in value]
    if isinstance(value, dict): return {_vary(k): _vary(v) for k,v in value.items()}
    return value
N = 1
observations = []
def solve(data):
    out=[]
    for cell in data:
        probe = cell
        if not cell.startswith("'") and probe[:1] in ('=', '+', '-', '@'):
            cell = "'" + cell
        cell = cell.replace('"', '""')
        out.append('"' + cell + '"')
    return ','.join(out) + '\n'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('formula', solve(_vary(['=1+1'])), _vary('"\'=1+1"\n'))
check('leading space', solve(_vary([' \t+2'])), _vary('"\' \t+2"\n'))
check('existing prefix', solve(_vary(["'=3"])), _vary('"\'=3"\n'))
check('minus', solve(_vary(['-12'])), _vary('"\'-12"\n'))
check('ordinary', solve(_vary(['text', 'a"b'])), _vary('"text","a""b"\n'))
check('empty', solve(_vary([''])), _vary('""\n'))
check('interior', solve(_vary(['x=1'])), _vary('"x=1"\n'))
check('no cells', solve(_vary([])), _vary('\n'))
check('variant formula width', solve(['='+str(N)+'+1']), '"\'='+str(N)+'+1"\n')
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
formula"'=1+1" "'=1+1" Passed
leading space" +2" "' +2" Failed
existing prefix"'=3" "'=3" Passed
minus"'-12" "'-12" Passed
ordinary"text","a""b" "text","a""b" Passed
empty"" "" Passed
interior"x=1" "x=1" Passed
no cells Passed
variant formula width"'=1+1" "'=1+1" Passed

SHA-256 / 7746d1ee5283eb63f5b2ca30d833bf26415553290ab167708cce5a8231d7d2ec

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
def _vary(value):
    if value == '@END': return 3 + 4*N
    if isinstance(value, str): return value.replace('@', 'cell' * N)
    if isinstance(value, list): return [_vary(x) for x in value]
    if isinstance(value, dict): return {_vary(k): _vary(v) for k,v in value.items()}
    return value
N = 1
observations = []
def solve(data):
    out=[]
    for cell in data:
        probe = cell.lstrip(' ')
        if not cell.startswith("'") and probe[:1] in ('=', '+', '-', '@'):
            cell = "'" + cell
        cell = cell.replace('"', '""')
        out.append('"' + cell + '"')
    return ','.join(out) + '\n'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('formula', solve(_vary(['=1+1'])), _vary('"\'=1+1"\n'))
check('leading space', solve(_vary([' \t+2'])), _vary('"\' \t+2"\n'))
check('existing prefix', solve(_vary(["'=3"])), _vary('"\'=3"\n'))
check('minus', solve(_vary(['-12'])), _vary('"\'-12"\n'))
check('ordinary', solve(_vary(['text', 'a"b'])), _vary('"text","a""b"\n'))
check('empty', solve(_vary([''])), _vary('""\n'))
check('interior', solve(_vary(['x=1'])), _vary('"x=1"\n'))
check('no cells', solve(_vary([])), _vary('\n'))
check('variant formula width', solve(['='+str(N)+'+1']), '"\'='+str(N)+'+1"\n')
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
formula"'=1+1" "'=1+1" Passed
leading space" +2" "' +2" Failed
existing prefix"'=3" "'=3" Passed
minus"'-12" "'-12" Passed
ordinary"text","a""b" "text","a""b" Passed
empty"" "" Passed
interior"x=1" "x=1" Passed
no cells Passed
variant formula width"'=1+1" "'=1+1" Passed

SHA-256 / bda0be4ac713b9e734cc66367905813f52476a9803e670b0aa03a826fb128e67

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
def _vary(value):
    if value == '@END': return 3 + 4*N
    if isinstance(value, str): return value.replace('@', 'cell' * N)
    if isinstance(value, list): return [_vary(x) for x in value]
    if isinstance(value, dict): return {_vary(k): _vary(v) for k,v in value.items()}
    return value
N = 1
observations = []
def solve(data):
    out=[]
    for cell in data:
        probe = cell.lstrip(' \t')
        if not cell.startswith("'") and probe[:1] in ('=', '+', '-', '@'):
            cell = "'" + cell
        cell = cell.replace('"', '""')
        out.append('"' + cell + '"')
    return ','.join(out) + '\n'
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('formula', solve(_vary(['=1+1'])), _vary('"\'=1+1"\n'))
check('leading space', solve(_vary([' \t+2'])), _vary('"\' \t+2"\n'))
check('existing prefix', solve(_vary(["'=3"])), _vary('"\'=3"\n'))
check('minus', solve(_vary(['-12'])), _vary('"\'-12"\n'))
check('ordinary', solve(_vary(['text', 'a"b'])), _vary('"text","a""b"\n'))
check('empty', solve(_vary([''])), _vary('""\n'))
check('interior', solve(_vary(['x=1'])), _vary('"x=1"\n'))
check('no cells', solve(_vary([])), _vary('\n'))
check('variant formula width', solve(['='+str(N)+'+1']), '"\'='+str(N)+'+1"\n')
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
formula"'=1+1" "'=1+1" Passed
leading space"' +2" "' +2" Passed
existing prefix"'=3" "'=3" Passed
minus"'-12" "'-12" Passed
ordinary"text","a""b" "text","a""b" Passed
empty"" "" Passed
interior"x=1" "x=1" Passed
no cells Passed
variant formula width"'=1+1" "'=1+1" Passed

SHA-256 / 8348ff28c929a532c9792033b193a797fe6e2e3c5e5cd5409b1465525f8e21b4

Verification & scope

Deterministic bounded in-memory model. No claim of complete CSV or external format conformance. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:44:47.802279+00:00.

Case digest / 04f8217b7b8ce9d28fb725eacc47a6ec836b609c60589d15e2abbfa5429359f6