FAILURE MAP
← Case archive

FA-3941 / Encodings / Open access

Unicode escape encoding mistakes literal escape text for a character · case 01

Unicode escape encoding mistakes literal escape text for a character.

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

ROOT CAUSE

The implementation applies an operation whose text or grammar semantics violate this contract: Encode Unicode text with Python unicode_escape and return ASCII text.

VERIFIED REPAIR

Implement the complete stated contract, including the boundary fixtures: Encode Unicode text with Python unicode_escape and return ASCII text.

Unsuccessful approach: The attempted repair handles the primary example but still violates a separate boundary of the same contract.

Case contract

Encode Unicode text with Python unicode_escape and return ASCII text.

Why this case matters

A local executable model for consumers of structured text; oracle values are authored literals, not outputs copied from the repaired implementation.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        return x
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve('\\u0041'), '\\\\u0041')
check('boundary 2', solve('\n'), '\\n')
check('boundary 3', solve('é'), '\\xe9')
check('boundary 4', solve('A'), 'A')
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
boundary 1\u0041\\u0041Failed
boundary 2 \nFailed
boundary 3é\xe9Failed
boundary 4AAPassed

SHA-256 / 7fc1c942da41fc8e4891563cedc35eef06f38886b485598ba37634912e417bee

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        return x.encode('ascii','backslashreplace').decode()
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve('\\u0041'), '\\\\u0041')
check('boundary 2', solve('\n'), '\\n')
check('boundary 3', solve('é'), '\\xe9')
check('boundary 4', solve('A'), 'A')
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
boundary 1\u0041\\u0041Failed
boundary 2 \nFailed
boundary 3\xe9\xe9Passed
boundary 4AAPassed

SHA-256 / 7f677b62b371c09ceaffd9fec74f409cfda67ace6b3bc5cf34bb5fa24a12ded3

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        return x.encode('unicode_escape').decode('ascii')
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve('\\u0041'), '\\\\u0041')
check('boundary 2', solve('\n'), '\\n')
check('boundary 3', solve('é'), '\\xe9')
check('boundary 4', solve('A'), 'A')
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
boundary 1\\u0041\\u0041Passed
boundary 2\n\nPassed
boundary 3\xe9\xe9Passed
boundary 4AAPassed

SHA-256 / 4fda854d30ecb25a6e9f59651c9605afc383da98ed04866e28f2dff223e23af2

Verification & scope

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

Case digest / cc335cd5b63943d194b0e0e7ea1b7dac285d652e87744fef0d52468cc36fe65e