FA-48121 / Delimited text / Open access
Formula neutralization inserts its marker after leading whitespace · case 01
A structured table violates the declared record or column contract.
ROOT CAUSE
Formula neutralization inserts its marker after leading whitespace.
VERIFIED REPAIR
Preserve the named invariant at the faulty decision: cell = "'" + cell
Unsuccessful approach: The alternate implementation still violates the same declared invariant: formula neutralization inserts its marker after 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.lstrip(' \t')
if not cell.startswith("'") and probe[:1] in ('=', '+', '-', '@'):
cell = cell[:len(cell)-len(probe)] + "'" + probe
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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 / 5c0d6b9ddd5d524040fe746084300df906d8d73573d0990be91106c008e481a0
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(' \t')
if not cell.startswith("'") and probe[:1] in ('=', '+', '-', '@'):
cell = probe + "'"
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| formula | "=1+1'"
| "'=1+1"
| Failed |
| leading space | "+2'"
| "' +2"
| Failed |
| existing prefix | "'=3"
| "'=3"
| Passed |
| minus | "-12'"
| "'-12"
| Failed |
| 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"
| Failed |
SHA-256 / 4552d91d583458d3f2e3d0b03c198cc838fd7b86d402678fb5850ef85fcdc7de
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 fixture | Actual | Expected | Outcome |
|---|---|---|---|
| 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.967164+00:00.
Case digest / 92550196125dd94b510b59f38178715d651ebba6f5184a0d4ec7b10136972867