FA-48151 / Delimited text / Open access
Whitespace before a comment is removed from the final field · case 01
A structured table violates the declared record or column contract.
ROOT CAUSE
Whitespace before a comment is removed from the final field.
VERIFIED REPAIR
Preserve the named invariant at the faulty decision: out.append(''.join(buf)) return out
Unsuccessful approach: The alternate implementation still violates the same declared invariant: whitespace before a comment is removed from the final field.
Case contract
Split a comma record with trailing comments. A # outside double quotes ends the record; inside quotes it is data. Quotes toggle quoted state and are removed; doubled quotes inside quotes emit one quote. Whitespace before a trailing comment is data. Unterminated quoting rejects.
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, buf, quoted, i = [], [], False, 0
while i < len(data):
ch=data[i]
if ch == '"':
if quoted and i+1 < len(data) and data[i+1] == '"':
buf.append('"'); i += 2; continue
quoted = not quoted
elif ch == '#' and not quoted: break
elif ch == ',' and not quoted:
out.append(''.join(buf)); buf=[]
else: buf.append(ch)
i += 1
if quoted: return None
out.append(''.join(buf).rstrip())
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('comment', solve(_vary('@,x#note')), _vary(['@', 'x']))
check('quoted marker', solve(_vary('"#@",x')), _vary(['#@', 'x']))
check('escaped quote', solve(_vary('"a""#b",z')), _vary(['a"#b', 'z']))
check('spaces', solve(_vary('@ #x')), _vary(['@ ']))
check('only comment', solve(_vary('#note')), _vary(['']))
check('unclosed', solve(_vary('"@#note')), _vary(None))
check('normal', solve(_vary('@,x')), _vary(['@', 'x']))
check('comment commas', solve(_vary('@#x,y')), _vary(['@']))
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 |
|---|---|---|---|
| comment | ['cell', 'x'] | ['cell', 'x'] | Passed |
| quoted marker | ['#cell', 'x'] | ['#cell', 'x'] | Passed |
| escaped quote | ['a"#b', 'z'] | ['a"#b', 'z'] | Passed |
| spaces | ['cell'] | ['cell '] | Failed |
| only comment | [''] | [''] | Passed |
| unclosed | None | None | Passed |
| normal | ['cell', 'x'] | ['cell', 'x'] | Passed |
| comment commas | ['cell'] | ['cell'] | Passed |
SHA-256 / 7fbd3d6f30431607b35f3ae2e5c7295ed3e6edd1b369b1b5b11e77cf5cfd5773
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, buf, quoted, i = [], [], False, 0
while i < len(data):
ch=data[i]
if ch == '"':
if quoted and i+1 < len(data) and data[i+1] == '"':
buf.append('"'); i += 2; continue
quoted = not quoted
elif ch == '#' and not quoted: break
elif ch == ',' and not quoted:
out.append(''.join(buf)); buf=[]
else: buf.append(ch)
i += 1
if quoted: return None
out.append(''.join(buf).strip())
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('comment', solve(_vary('@,x#note')), _vary(['@', 'x']))
check('quoted marker', solve(_vary('"#@",x')), _vary(['#@', 'x']))
check('escaped quote', solve(_vary('"a""#b",z')), _vary(['a"#b', 'z']))
check('spaces', solve(_vary('@ #x')), _vary(['@ ']))
check('only comment', solve(_vary('#note')), _vary(['']))
check('unclosed', solve(_vary('"@#note')), _vary(None))
check('normal', solve(_vary('@,x')), _vary(['@', 'x']))
check('comment commas', solve(_vary('@#x,y')), _vary(['@']))
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 |
|---|---|---|---|
| comment | ['cell', 'x'] | ['cell', 'x'] | Passed |
| quoted marker | ['#cell', 'x'] | ['#cell', 'x'] | Passed |
| escaped quote | ['a"#b', 'z'] | ['a"#b', 'z'] | Passed |
| spaces | ['cell'] | ['cell '] | Failed |
| only comment | [''] | [''] | Passed |
| unclosed | None | None | Passed |
| normal | ['cell', 'x'] | ['cell', 'x'] | Passed |
| comment commas | ['cell'] | ['cell'] | Passed |
SHA-256 / 005c67f39002fe725eb91cdcfce6c4705953c19e82ee8f1000a9d4a812d44e36
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, buf, quoted, i = [], [], False, 0
while i < len(data):
ch=data[i]
if ch == '"':
if quoted and i+1 < len(data) and data[i+1] == '"':
buf.append('"'); i += 2; continue
quoted = not quoted
elif ch == '#' and not quoted: break
elif ch == ',' and not quoted:
out.append(''.join(buf)); buf=[]
else: buf.append(ch)
i += 1
if quoted: return None
out.append(''.join(buf))
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('comment', solve(_vary('@,x#note')), _vary(['@', 'x']))
check('quoted marker', solve(_vary('"#@",x')), _vary(['#@', 'x']))
check('escaped quote', solve(_vary('"a""#b",z')), _vary(['a"#b', 'z']))
check('spaces', solve(_vary('@ #x')), _vary(['@ ']))
check('only comment', solve(_vary('#note')), _vary(['']))
check('unclosed', solve(_vary('"@#note')), _vary(None))
check('normal', solve(_vary('@,x')), _vary(['@', 'x']))
check('comment commas', solve(_vary('@#x,y')), _vary(['@']))
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 |
|---|---|---|---|
| comment | ['cell', 'x'] | ['cell', 'x'] | Passed |
| quoted marker | ['#cell', 'x'] | ['#cell', 'x'] | Passed |
| escaped quote | ['a"#b', 'z'] | ['a"#b', 'z'] | Passed |
| spaces | ['cell '] | ['cell '] | Passed |
| only comment | [''] | [''] | Passed |
| unclosed | None | None | Passed |
| normal | ['cell', 'x'] | ['cell', 'x'] | Passed |
| comment commas | ['cell'] | ['cell'] | Passed |
SHA-256 / 015bbb11965f644930fe00f62300281bc9d252e6724a34460de3f6edbc924bcb
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:48.157370+00:00.
Case digest / 978f2f0416748d0cc7befbb295265835ecc5ae1d2d2bc325def31d1595a747f9