FA-48156 / Delimited text / Open access
The second quote of an escaped pair is revisited as syntax · case 01
A structured table violates the declared record or column contract.
ROOT CAUSE
The second quote of an escaped pair is revisited as syntax.
VERIFIED REPAIR
Preserve the named invariant at the faulty decision: buf.append('"'); i += 2; continue
Unsuccessful approach: The alternate implementation still violates the same declared invariant: the second quote of an escaped pair is revisited as syntax.
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 += 1; 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"'] | ['a"#b', 'z'] | Failed |
| spaces | ['cell '] | ['cell '] | Passed |
| only comment | [''] | [''] | Passed |
| unclosed | None | None | Passed |
| normal | ['cell', 'x'] | ['cell', 'x'] | Passed |
| comment commas | ['cell'] | ['cell'] | Passed |
SHA-256 / 23cf9066cc724d0bea0686034a1b3e8e373d5d42f875c5aa73fdee18d7abc380
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 += 3; 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'] | Failed |
| spaces | ['cell '] | ['cell '] | Passed |
| only comment | [''] | [''] | Passed |
| unclosed | None | None | Passed |
| normal | ['cell', 'x'] | ['cell', 'x'] | Passed |
| comment commas | ['cell'] | ['cell'] | Passed |
SHA-256 / 1334e7af3f346860339fba5728f22857c31b16025f5d040ae2cfdfda251a87e5
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.174117+00:00.
Case digest / 19004061c9b0cb5494f0afc468ff89941e4f318ba0fed74a37f523c290f220c6