FA-47416 / Delimited text / Open access
A TSV writer leaves literal escape prefixes ambiguous · case 01
A structured table violates the declared record or column contract.
ROOT CAUSE
Existing backslashes are not escaped before control escapes are introduced.
VERIFIED REPAIR
Preserve the named invariant at the faulty decision: field = field.replace('\\', '\\\\')
Unsuccessful approach: Escaping only slash-t misses bare slashes and other escape-looking text.
Case contract
Encode a list of text cells as TSV without a terminator. Escape backslashes before introducing backslash-t, backslash-n, backslash-r; preserve empty columns and all other text.
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 field in data:
field = field
field = field.replace('\t', '\\t')
field = field.replace('\n', '\\n')
field = field.replace('\r', '\\r')
out.append(field)
return '\t'.join(out)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('all controls', solve(_vary(['@\t\n\r\\'])), _vary('@\\t\\n\\r\\\\'))
check('empty cells', solve(_vary(['', '@', ''])), _vary('\t@\t'))
check('literal slash-t', solve(_vary(['\\t'])), _vary('\\\\t'))
check('normal', solve(_vary(['@', 'x'])), _vary('@\tx'))
check('zero columns', solve(_vary([])), _vary(''))
check('all empty', solve(_vary(['', '', ''])), _vary('\t\t'))
check('LF only', solve(_vary(['\n'])), _vary('\\n'))
check('CR only', solve(_vary(['\r'])), _vary('\\r'))
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 |
|---|---|---|---|
| all controls | cell\t\n\r\ | cell\t\n\r\\ | Failed |
| empty cells | cell | cell | Passed |
| literal slash-t | \t | \\t | Failed |
| normal | cell x | cell x | Passed |
| zero columns | | | Passed |
| all empty | | | Passed |
| LF only | \n | \n | Passed |
| CR only | \r | \r | Passed |
SHA-256 / 14fae5d1302f1d325a05591c1344a578b7d942e2022f8526dfb67af17f63fddd
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 field in data:
field = field.replace('\\t', '\\\\t')
field = field.replace('\t', '\\t')
field = field.replace('\n', '\\n')
field = field.replace('\r', '\\r')
out.append(field)
return '\t'.join(out)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('all controls', solve(_vary(['@\t\n\r\\'])), _vary('@\\t\\n\\r\\\\'))
check('empty cells', solve(_vary(['', '@', ''])), _vary('\t@\t'))
check('literal slash-t', solve(_vary(['\\t'])), _vary('\\\\t'))
check('normal', solve(_vary(['@', 'x'])), _vary('@\tx'))
check('zero columns', solve(_vary([])), _vary(''))
check('all empty', solve(_vary(['', '', ''])), _vary('\t\t'))
check('LF only', solve(_vary(['\n'])), _vary('\\n'))
check('CR only', solve(_vary(['\r'])), _vary('\\r'))
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 |
|---|---|---|---|
| all controls | cell\t\n\r\ | cell\t\n\r\\ | Failed |
| empty cells | cell | cell | Passed |
| literal slash-t | \\t | \\t | Passed |
| normal | cell x | cell x | Passed |
| zero columns | | | Passed |
| all empty | | | Passed |
| LF only | \n | \n | Passed |
| CR only | \r | \r | Passed |
SHA-256 / fd2719f2b8b8005b843e97ec1c83bdf0ce1fdaf9aca000bc6bc089f857260d6f
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 field in data:
field = field.replace('\\', '\\\\')
field = field.replace('\t', '\\t')
field = field.replace('\n', '\\n')
field = field.replace('\r', '\\r')
out.append(field)
return '\t'.join(out)
def check(label, actual, expected):
observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('all controls', solve(_vary(['@\t\n\r\\'])), _vary('@\\t\\n\\r\\\\'))
check('empty cells', solve(_vary(['', '@', ''])), _vary('\t@\t'))
check('literal slash-t', solve(_vary(['\\t'])), _vary('\\\\t'))
check('normal', solve(_vary(['@', 'x'])), _vary('@\tx'))
check('zero columns', solve(_vary([])), _vary(''))
check('all empty', solve(_vary(['', '', ''])), _vary('\t\t'))
check('LF only', solve(_vary(['\n'])), _vary('\\n'))
check('CR only', solve(_vary(['\r'])), _vary('\\r'))
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 |
|---|---|---|---|
| all controls | cell\t\n\r\\ | cell\t\n\r\\ | Passed |
| empty cells | cell | cell | Passed |
| literal slash-t | \\t | \\t | Passed |
| normal | cell x | cell x | Passed |
| zero columns | | | Passed |
| all empty | | | Passed |
| LF only | \n | \n | Passed |
| CR only | \r | \r | Passed |
SHA-256 / cb59a0aeadc5359c537e056b45d1753eb2d79c66b37674bf20822e8768925ba6
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.267071+00:00.
Case digest / 24e716ca4bca551dfa71e8db369d83bb56dfc7f32835861e7868a2d0ba0bca80