FAILURE MAP
← Case archive

FA-47471 / Delimited text / Open access

An escaped quote closes a field prematurely · case 01

A structured table violates the declared record or column contract.

Verified by executionVariant 1 · 16 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

After a doubled quote the automaton remains in the closing state.

THE FAILURE

After a doubled quote the automaton remains in the closing state.

Unsuccessful approach: Returning to field-start state loses the enclosing quoted context.

Case contract

Lex one physical comma record. A quote opens only at field start; doubled quotes decode inside quoted fields; after a closing quote only comma or EOF is legal. CR/LF outside quoted fields reject. Return fields and quote-origin flags; a physical newline inside quoted text remains literal.

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):
    result, buf, state, origin = [], [], 'start', False
    for ch in data:
        if state == 'quoted':
            if ch == '"': state = 'closed'
            else: buf.append(ch)
        elif state == 'closed':
            if ch == '"':
                buf.append('"')
                state = 'closed'
            elif ch == ',':
                result.append([''.join(buf), origin])
                buf, state, origin = [], 'start', False
            else: return None
        elif ch == ',':
            result.append([''.join(buf), origin])
            buf, state, origin = [], 'start', False
        elif ch == '"':
            if state != 'start': return None
            state, origin = 'quoted', True
        elif ch in '\r\n': return None
        else:
            buf.append(ch)
            state = 'bare'
    if state == 'quoted': return None
    result.append([''.join(buf), origin])
    return result
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('quoted flags', solve(_vary('"@",a')), _vary([['@', True], ['a', False]]))
check('doubled', solve(_vary('"a""b"')), _vary([['a"b', True]]))
check('triple ending', solve(_vary('"@"""')), _vary([['@"', True]]))
check('empty quoted', solve(_vary('""')), _vary([['', True]]))
check('empty bare', solve(_vary('')), _vary([['', False]]))
check('suffix comma', solve(_vary('"@",')), _vary([['@', True], ['', False]]))
check('bare quote', solve(_vary('a"b')), _vary(None))
check('balanced quote suffix', solve(_vary('a"b"')), _vary(None))
check('junk closing', solve(_vary('"a"x')), _vary(None))
check('space closing', solve(_vary('"a" ')), _vary(None))
check('quoted newlines', solve(_vary('"a\nb"')), _vary([['a\nb', True]]))
check('quoted carriage return', solve(_vary('"a\rb"')), _vary([['a\rb', True]]))
check('unquoted newline', solve(_vary('a\nb')), _vary(None))
check('two quoted', solve(_vary('"a","b"')), _vary([['a', True], ['b', True]]))
check('unterminated', solve(_vary('"a')), _vary(None))
check('plain', solve(_vary('@,z')), _vary([['@', False], ['z', False]]))
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 fixtureActualExpectedOutcome
quoted flags[['cell', True], ['a', False]][['cell', True], ['a', False]]Passed
doubledNone[['a"b', True]]Failed
triple ending[['cell""', True]][['cell"', True]]Failed
empty quoted[['', True]][['', True]]Passed
empty bare[['', False]][['', False]]Passed
suffix comma[['cell', True], ['', False]][['cell', True], ['', False]]Passed
bare quoteNoneNonePassed
balanced quote suffixNoneNonePassed
junk closingNoneNonePassed
space closingNoneNonePassed
quoted newlines[['a\nb', True]][['a\nb', True]]Passed
quoted carriage return[['a\rb', True]][['a\rb', True]]Passed
unquoted newlineNoneNonePassed
two quoted[['a', True], ['b', True]][['a', True], ['b', True]]Passed
unterminatedNoneNonePassed
plain[['cell', False], ['z', False]][['cell', False], ['z', False]]Passed

SHA-256 / b49ee5af976fe172b0d969ee48cdf1e32e368742ba5123dc032b7b1693c42695

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):
    result, buf, state, origin = [], [], 'start', False
    for ch in data:
        if state == 'quoted':
            if ch == '"': state = 'closed'
            else: buf.append(ch)
        elif state == 'closed':
            if ch == '"':
                buf.append('"')
                state = 'start'
            elif ch == ',':
                result.append([''.join(buf), origin])
                buf, state, origin = [], 'start', False
            else: return None
        elif ch == ',':
            result.append([''.join(buf), origin])
            buf, state, origin = [], 'start', False
        elif ch == '"':
            if state != 'start': return None
            state, origin = 'quoted', True
        elif ch in '\r\n': return None
        else:
            buf.append(ch)
            state = 'bare'
    if state == 'quoted': return None
    result.append([''.join(buf), origin])
    return result
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('quoted flags', solve(_vary('"@",a')), _vary([['@', True], ['a', False]]))
check('doubled', solve(_vary('"a""b"')), _vary([['a"b', True]]))
check('triple ending', solve(_vary('"@"""')), _vary([['@"', True]]))
check('empty quoted', solve(_vary('""')), _vary([['', True]]))
check('empty bare', solve(_vary('')), _vary([['', False]]))
check('suffix comma', solve(_vary('"@",')), _vary([['@', True], ['', False]]))
check('bare quote', solve(_vary('a"b')), _vary(None))
check('balanced quote suffix', solve(_vary('a"b"')), _vary(None))
check('junk closing', solve(_vary('"a"x')), _vary(None))
check('space closing', solve(_vary('"a" ')), _vary(None))
check('quoted newlines', solve(_vary('"a\nb"')), _vary([['a\nb', True]]))
check('quoted carriage return', solve(_vary('"a\rb"')), _vary([['a\rb', True]]))
check('unquoted newline', solve(_vary('a\nb')), _vary(None))
check('two quoted', solve(_vary('"a","b"')), _vary([['a', True], ['b', True]]))
check('unterminated', solve(_vary('"a')), _vary(None))
check('plain', solve(_vary('@,z')), _vary([['@', False], ['z', False]]))
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 fixtureActualExpectedOutcome
quoted flags[['cell', True], ['a', False]][['cell', True], ['a', False]]Passed
doubledNone[['a"b', True]]Failed
triple endingNone[['cell"', True]]Failed
empty quoted[['', True]][['', True]]Passed
empty bare[['', False]][['', False]]Passed
suffix comma[['cell', True], ['', False]][['cell', True], ['', False]]Passed
bare quoteNoneNonePassed
balanced quote suffixNoneNonePassed
junk closingNoneNonePassed
space closingNoneNonePassed
quoted newlines[['a\nb', True]][['a\nb', True]]Passed
quoted carriage return[['a\rb', True]][['a\rb', True]]Passed
unquoted newlineNoneNonePassed
two quoted[['a', True], ['b', True]][['a', True], ['b', True]]Passed
unterminatedNoneNonePassed
plain[['cell', False], ['z', False]][['cell', False], ['z', False]]Passed

SHA-256 / ad2099071a9395fd60370ed3aa3fa961d666c6d3f5e6adeff29895e8d1dc6f04

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 16 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

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:42.093942+00:00.

Case digest / 1274940597cd803412e7d7efccd574580178baaa40112147fe38481c2a88d92c