FA-47406 / Delimited text / Open access
Raw newlines are accepted inside a one-record TSV API · case 01
A structured table violates the declared record or column contract.
ROOT CAUSE
The single-record reader permits physical row terminators as cell data.
VERIFIED REPAIR
Preserve the named invariant at the faulty decision: elif ch in '\r\n': return None
Unsuccessful approach: Rejecting carriage returns alone still admits a raw line feed.
Case contract
Decode TSV fields with exactly four escapes: backslash-t, backslash-n, backslash-r, backslash-backslash. Raw tabs split fields, raw newlines are forbidden; unknown and dangling escapes reject the row. Empty input is one empty field.
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, field, escaped = [], [], False
for ch in data:
if escaped:
if ch not in 'tnr\\': return None
field.append({'t':'\t','n':'\n','r':'\r','\\':'\\'}[ch])
escaped = False
elif ch == '\\': escaped = True
elif ch == '\t':
out.append(''.join(field))
field = []
elif False: return None
else: field.append(ch)
if escaped: return None
out.append(''.join(field))
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('mapped escapes', solve(_vary('@\\tA\\nB\\rC\\\\D')), _vary(['@\tA\nB\rC\\D']))
check('separators', solve(_vary('@\t\tZ')), _vary(['@', '', 'Z']))
check('escaped backslash then t', solve(_vary('\\\\t')), _vary(['\\t']))
check('unknown', solve(_vary('\\q')), _vary(None))
check('dangling', solve(_vary('@\\')), _vary(None))
check('raw newline', solve(_vary('@\nZ')), _vary(None))
check('empty', solve(_vary('')), _vary(['']))
check('leading trailing', solve(_vary('\t@\t')), _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 |
|---|---|---|---|
| mapped escapes | ['cell\tA\nB\rC\\D'] | ['cell\tA\nB\rC\\D'] | Passed |
| separators | ['cell', '', 'Z'] | ['cell', '', 'Z'] | Passed |
| escaped backslash then t | ['\\t'] | ['\\t'] | Passed |
| unknown | None | None | Passed |
| dangling | None | None | Passed |
| raw newline | ['cell\nZ'] | None | Failed |
| empty | [''] | [''] | Passed |
| leading trailing | ['', 'cell', ''] | ['', 'cell', ''] | Passed |
SHA-256 / 04ef1b64beea97a4918c4cbf6a5cd549dc9273215e04540b0130af0196766098
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, field, escaped = [], [], False
for ch in data:
if escaped:
if ch not in 'tnr\\': return None
field.append({'t':'\t','n':'\n','r':'\r','\\':'\\'}[ch])
escaped = False
elif ch == '\\': escaped = True
elif ch == '\t':
out.append(''.join(field))
field = []
elif ch == '\r': return None
else: field.append(ch)
if escaped: return None
out.append(''.join(field))
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('mapped escapes', solve(_vary('@\\tA\\nB\\rC\\\\D')), _vary(['@\tA\nB\rC\\D']))
check('separators', solve(_vary('@\t\tZ')), _vary(['@', '', 'Z']))
check('escaped backslash then t', solve(_vary('\\\\t')), _vary(['\\t']))
check('unknown', solve(_vary('\\q')), _vary(None))
check('dangling', solve(_vary('@\\')), _vary(None))
check('raw newline', solve(_vary('@\nZ')), _vary(None))
check('empty', solve(_vary('')), _vary(['']))
check('leading trailing', solve(_vary('\t@\t')), _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 |
|---|---|---|---|
| mapped escapes | ['cell\tA\nB\rC\\D'] | ['cell\tA\nB\rC\\D'] | Passed |
| separators | ['cell', '', 'Z'] | ['cell', '', 'Z'] | Passed |
| escaped backslash then t | ['\\t'] | ['\\t'] | Passed |
| unknown | None | None | Passed |
| dangling | None | None | Passed |
| raw newline | ['cell\nZ'] | None | Failed |
| empty | [''] | [''] | Passed |
| leading trailing | ['', 'cell', ''] | ['', 'cell', ''] | Passed |
SHA-256 / ea47dc5cf65fed7eeca18086ec4b38e0d3879e9b089ebb514d21a30c109d788c
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, field, escaped = [], [], False
for ch in data:
if escaped:
if ch not in 'tnr\\': return None
field.append({'t':'\t','n':'\n','r':'\r','\\':'\\'}[ch])
escaped = False
elif ch == '\\': escaped = True
elif ch == '\t':
out.append(''.join(field))
field = []
elif ch in '\r\n': return None
else: field.append(ch)
if escaped: return None
out.append(''.join(field))
return out
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('mapped escapes', solve(_vary('@\\tA\\nB\\rC\\\\D')), _vary(['@\tA\nB\rC\\D']))
check('separators', solve(_vary('@\t\tZ')), _vary(['@', '', 'Z']))
check('escaped backslash then t', solve(_vary('\\\\t')), _vary(['\\t']))
check('unknown', solve(_vary('\\q')), _vary(None))
check('dangling', solve(_vary('@\\')), _vary(None))
check('raw newline', solve(_vary('@\nZ')), _vary(None))
check('empty', solve(_vary('')), _vary(['']))
check('leading trailing', solve(_vary('\t@\t')), _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 |
|---|---|---|---|
| mapped escapes | ['cell\tA\nB\rC\\D'] | ['cell\tA\nB\rC\\D'] | Passed |
| separators | ['cell', '', 'Z'] | ['cell', '', 'Z'] | Passed |
| escaped backslash then t | ['\\t'] | ['\\t'] | Passed |
| unknown | None | None | Passed |
| dangling | None | None | Passed |
| raw newline | None | None | Passed |
| empty | [''] | [''] | Passed |
| leading trailing | ['', 'cell', ''] | ['', 'cell', ''] | Passed |
SHA-256 / 98c681e1d643b08c156bd53a4503ea6ecd2ea6bf8f46c1fef0a558a502918826
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:41.103548+00:00.
Case digest / 117a965544c8411a9fe17d8603bd35f39031a5258199fc461711355d6d795353