FAILURE MAP
← Case archive

FA-3106 / Regular expressions / Open access

Replacement backslashes become regex instructions · case 01

Replacement backslashes become regex instructions.

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: Replace every X with the literal replacement x[1] in x[0].

VERIFIED REPAIR

Implement the complete stated contract, including the boundary fixtures: Replace every X with the literal replacement x[1] in x[0].

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

Case contract

Replace every X with the literal replacement x[1] in x[0].

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 re.sub('X',x[1],x[0])
    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(['XX', '\\n']), '\\n\\n')
check('boundary 2', solve(['aX', 'z']), 'az')
check('boundary 3', solve(['none', 'x']), 'none')
check('boundary 4', solve(['X', '\\g<0>']), '\\g<0>')
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 \n\nFailed
boundary 2azazPassed
boundary 3nonenonePassed
boundary 4X\g<0>Failed

SHA-256 / c8959cb176dfaa138a6f7e59596822a4d2ba44d5e62186c2f33b93f29b9ddc16

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 re.sub('X',x[1].replace('\\','\\\\'),x[0],count=1)
    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(['XX', '\\n']), '\\n\\n')
check('boundary 2', solve(['aX', 'z']), 'az')
check('boundary 3', solve(['none', 'x']), 'none')
check('boundary 4', solve(['X', '\\g<0>']), '\\g<0>')
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\nX\n\nFailed
boundary 2azazPassed
boundary 3nonenonePassed
boundary 4\g<0>\g<0>Passed

SHA-256 / 4c4317c17717a45218d9b61928b08d5b4ff32532892e74bfbbe52d32e187ddb4

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 re.sub('X',lambda m:x[1],x[0])
    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(['XX', '\\n']), '\\n\\n')
check('boundary 2', solve(['aX', 'z']), 'az')
check('boundary 3', solve(['none', 'x']), 'none')
check('boundary 4', solve(['X', '\\g<0>']), '\\g<0>')
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\n\n\n\nPassed
boundary 2azazPassed
boundary 3nonenonePassed
boundary 4\g<0>\g<0>Passed

SHA-256 / 5da2262980ff3cf35f76c32cbad6a4a5957761dc5abb5cbf779423c8d6318d7c

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

Case digest / f9847349de7880df29f6d4ba82782569f3c8a9a094bdf7ba9715f322c3349f16