broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(tree):
    def walk(n):
        t = n['type'].lower()
        disp = (n.get('disp') or 'inline').lower()
        if t == 'multipart/alternative':
            for child in reversed(n['parts']):
                got = walk(child)
                if got:
                    return got
            return []
        if t.startswith('multipart/'):
            out = []
            for child in n['parts']:
                out.extend(walk(child))
            return out
        if t == 'message/rfc822':
            return walk(n['body'])
        if disp == 'attachment':
            return []
        if t == 'text/plain':
            return [n['text']]
        return []
    return walk(tree)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('richer alternative holds text', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'A1'}, {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'B1'}, {'type': 'image/png'}]}]},), ['B1']), ('html last alternative', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'plain 1'}, {'type': 'text/html'}]},), ['plain 1']), ('attached message and log', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'hi'}, {'type': 'message/rfc822', 'disp': 'attachment', 'body': {'type': 'text/plain', 'text': 'inner'}}, {'type': 'text/plain', 'disp': 'attachment', 'text': 'log 1'}]},), ['hi']), ('inline forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'x'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'fw1'}, {'type': 'text/html'}]}}]},), ['x', 'fw1']), ('mixed-case types', ({'type': 'MULTIPART/Mixed', 'parts': [{'type': 'Text/Plain', 'text': 't1'}, {'type': 'TEXT/PLAIN', 'text': 'u'}]},), ['t1', 'u']), ('no text at all', ({'type': 'multipart/mixed', 'parts': [{'type': 'image/png'}, {'type': 'application/pdf'}]},), [])], 2: [('richer alternative holds text', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'A2'}, {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'B2'}, {'type': 'image/png'}]}]},), ['B2']), ('html last alternative', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'plain 2'}, {'type': 'text/html'}]},), ['plain 2']), ('attached message and log', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'hi'}, {'type': 'message/rfc822', 'disp': 'attachment', 'body': {'type': 'text/plain', 'text': 'inner'}}, {'type': 'text/plain', 'disp': 'attachment', 'text': 'log 2'}]},), ['hi']), ('inline forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'x'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'fw2'}, {'type': 'text/html'}]}}]},), ['x', 'fw2']), ('mixed-case types', ({'type': 'MULTIPART/Mixed', 'parts': [{'type': 'Text/Plain', 'text': 't2'}, {'type': 'TEXT/PLAIN', 'text': 'u'}]},), ['t2', 'u']), ('no text at all', ({'type': 'multipart/mixed', 'parts': [{'type': 'image/png'}, {'type': 'application/pdf'}]},), [])], 3: [('richer alternative holds text', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'A3'}, {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'B3'}, {'type': 'image/png'}]}]},), ['B3']), ('html last alternative', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'plain 3'}, {'type': 'text/html'}]},), ['plain 3']), ('attached message and log', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'hi'}, {'type': 'message/rfc822', 'disp': 'attachment', 'body': {'type': 'text/plain', 'text': 'inner'}}, {'type': 'text/plain', 'disp': 'attachment', 'text': 'log 3'}]},), ['hi']), ('inline forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'x'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'fw3'}, {'type': 'text/html'}]}}]},), ['x', 'fw3']), ('mixed-case types', ({'type': 'MULTIPART/Mixed', 'parts': [{'type': 'Text/Plain', 'text': 't3'}, {'type': 'TEXT/PLAIN', 'text': 'u'}]},), ['t3', 'u']), ('no text at all', ({'type': 'multipart/mixed', 'parts': [{'type': 'image/png'}, {'type': 'application/pdf'}]},), [])], 4: [('richer alternative holds text', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'A4'}, {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'B4'}, {'type': 'image/png'}]}]},), ['B4']), ('html last alternative', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'plain 4'}, {'type': 'text/html'}]},), ['plain 4']), ('attached message and log', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'hi'}, {'type': 'message/rfc822', 'disp': 'attachment', 'body': {'type': 'text/plain', 'text': 'inner'}}, {'type': 'text/plain', 'disp': 'attachment', 'text': 'log 4'}]},), ['hi']), ('inline forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'x'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'fw4'}, {'type': 'text/html'}]}}]},), ['x', 'fw4']), ('mixed-case types', ({'type': 'MULTIPART/Mixed', 'parts': [{'type': 'Text/Plain', 'text': 't4'}, {'type': 'TEXT/PLAIN', 'text': 'u'}]},), ['t4', 'u']), ('no text at all', ({'type': 'multipart/mixed', 'parts': [{'type': 'image/png'}, {'type': 'application/pdf'}]},), [])], 5: [('richer alternative holds text', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'A5'}, {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'B5'}, {'type': 'image/png'}]}]},), ['B5']), ('html last alternative', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'plain 5'}, {'type': 'text/html'}]},), ['plain 5']), ('attached message and log', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'hi'}, {'type': 'message/rfc822', 'disp': 'attachment', 'body': {'type': 'text/plain', 'text': 'inner'}}, {'type': 'text/plain', 'disp': 'attachment', 'text': 'log 5'}]},), ['hi']), ('inline forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'x'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'fw5'}, {'type': 'text/html'}]}}]},), ['x', 'fw5']), ('mixed-case types', ({'type': 'MULTIPART/Mixed', 'parts': [{'type': 'Text/Plain', 'text': 't5'}, {'type': 'TEXT/PLAIN', 'text': 'u'}]},), ['t5', 'u']), ('no text at all', ({'type': 'multipart/mixed', 'parts': [{'type': 'image/png'}, {'type': 'application/pdf'}]},), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(tree):
    def walk(n):
        t = n['type'].lower()
        disp = (n.get('disp') or 'inline').lower()
        if t == 'multipart/alternative':
            for child in reversed(n['parts']):
                got = walk(child)
                if got:
                    return got
            return []
        if t.startswith('multipart/'):
            out = []
            for child in n['parts']:
                out.extend(walk(child))
            return out
        if disp == 'attachment' and t != 'text/plain':
            return []
        if t == 'message/rfc822':
            return walk(n['body'])
        if t == 'text/plain':
            return [n['text']]
        return []
    return walk(tree)
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('richer alternative holds text', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'A1'}, {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'B1'}, {'type': 'image/png'}]}]},), ['B1']), ('html last alternative', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'plain 1'}, {'type': 'text/html'}]},), ['plain 1']), ('attached message and log', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'hi'}, {'type': 'message/rfc822', 'disp': 'attachment', 'body': {'type': 'text/plain', 'text': 'inner'}}, {'type': 'text/plain', 'disp': 'attachment', 'text': 'log 1'}]},), ['hi']), ('inline forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'x'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'fw1'}, {'type': 'text/html'}]}}]},), ['x', 'fw1']), ('mixed-case types', ({'type': 'MULTIPART/Mixed', 'parts': [{'type': 'Text/Plain', 'text': 't1'}, {'type': 'TEXT/PLAIN', 'text': 'u'}]},), ['t1', 'u']), ('no text at all', ({'type': 'multipart/mixed', 'parts': [{'type': 'image/png'}, {'type': 'application/pdf'}]},), [])], 2: [('richer alternative holds text', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'A2'}, {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'B2'}, {'type': 'image/png'}]}]},), ['B2']), ('html last alternative', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'plain 2'}, {'type': 'text/html'}]},), ['plain 2']), ('attached message and log', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'hi'}, {'type': 'message/rfc822', 'disp': 'attachment', 'body': {'type': 'text/plain', 'text': 'inner'}}, {'type': 'text/plain', 'disp': 'attachment', 'text': 'log 2'}]},), ['hi']), ('inline forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'x'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'fw2'}, {'type': 'text/html'}]}}]},), ['x', 'fw2']), ('mixed-case types', ({'type': 'MULTIPART/Mixed', 'parts': [{'type': 'Text/Plain', 'text': 't2'}, {'type': 'TEXT/PLAIN', 'text': 'u'}]},), ['t2', 'u']), ('no text at all', ({'type': 'multipart/mixed', 'parts': [{'type': 'image/png'}, {'type': 'application/pdf'}]},), [])], 3: [('richer alternative holds text', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'A3'}, {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'B3'}, {'type': 'image/png'}]}]},), ['B3']), ('html last alternative', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'plain 3'}, {'type': 'text/html'}]},), ['plain 3']), ('attached message and log', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'hi'}, {'type': 'message/rfc822', 'disp': 'attachment', 'body': {'type': 'text/plain', 'text': 'inner'}}, {'type': 'text/plain', 'disp': 'attachment', 'text': 'log 3'}]},), ['hi']), ('inline forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'x'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'fw3'}, {'type': 'text/html'}]}}]},), ['x', 'fw3']), ('mixed-case types', ({'type': 'MULTIPART/Mixed', 'parts': [{'type': 'Text/Plain', 'text': 't3'}, {'type': 'TEXT/PLAIN', 'text': 'u'}]},), ['t3', 'u']), ('no text at all', ({'type': 'multipart/mixed', 'parts': [{'type': 'image/png'}, {'type': 'application/pdf'}]},), [])], 4: [('richer alternative holds text', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'A4'}, {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'B4'}, {'type': 'image/png'}]}]},), ['B4']), ('html last alternative', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'plain 4'}, {'type': 'text/html'}]},), ['plain 4']), ('attached message and log', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'hi'}, {'type': 'message/rfc822', 'disp': 'attachment', 'body': {'type': 'text/plain', 'text': 'inner'}}, {'type': 'text/plain', 'disp': 'attachment', 'text': 'log 4'}]},), ['hi']), ('inline forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'x'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'fw4'}, {'type': 'text/html'}]}}]},), ['x', 'fw4']), ('mixed-case types', ({'type': 'MULTIPART/Mixed', 'parts': [{'type': 'Text/Plain', 'text': 't4'}, {'type': 'TEXT/PLAIN', 'text': 'u'}]},), ['t4', 'u']), ('no text at all', ({'type': 'multipart/mixed', 'parts': [{'type': 'image/png'}, {'type': 'application/pdf'}]},), [])], 5: [('richer alternative holds text', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'A5'}, {'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'B5'}, {'type': 'image/png'}]}]},), ['B5']), ('html last alternative', ({'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'plain 5'}, {'type': 'text/html'}]},), ['plain 5']), ('attached message and log', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'hi'}, {'type': 'message/rfc822', 'disp': 'attachment', 'body': {'type': 'text/plain', 'text': 'inner'}}, {'type': 'text/plain', 'disp': 'attachment', 'text': 'log 5'}]},), ['hi']), ('inline forwarded alternative', ({'type': 'multipart/mixed', 'parts': [{'type': 'text/plain', 'text': 'x'}, {'type': 'message/rfc822', 'body': {'type': 'multipart/alternative', 'parts': [{'type': 'text/plain', 'text': 'fw5'}, {'type': 'text/html'}]}}]},), ['x', 'fw5']), ('mixed-case types', ({'type': 'MULTIPART/Mixed', 'parts': [{'type': 'Text/Plain', 'text': 't5'}, {'type': 'TEXT/PLAIN', 'text': 'u'}]},), ['t5', 'u']), ('no text at all', ({'type': 'multipart/mixed', 'parts': [{'type': 'image/png'}, {'type': 'application/pdf'}]},), [])]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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)

prompt:
The text of an attached message is shown as part of the body.

Returns the text/plain strings to display in order. Types compare case-insensitively. multipart/alternative yields the result of its last child that yields any text; other multiparts concatenate their children. Entities with an attachment disposition yield nothing. A message/rfc822 without attachment disposition yields its body; text/plain yields its text; everything else yields nothing.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from urllib.parse import unquote_to_bytes
N = 1
observations = []
def solve(params):
    single = None
    plain = None
    segs = {}
    for name, value in params:
        n = name.lower()
        if n == 'filename*':
            single = value
        elif n == 'filename':
            plain = value
        elif n.startswith('filename*'):
            rest = n[9:]
            enc = rest.endswith('*')
            num = rest[:-1] if enc else rest
            if num.isdigit() and (num == '0' or not num.startswith('0')):
                segs[int(num)] = (enc, value)
    def codec(cs):
        cs = (cs or 'us-ascii').lower()
        return cs if cs in ('utf-8', 'iso-8859-1', 'us-ascii') else 'utf-8'
    if single is not None:
        cs, _, rest = single.partition("'")
        _, _, value = rest.partition("'")
        return unquote_to_bytes(value).decode(codec(cs), 'replace')
    if 0 not in segs:
        return plain
    charset = 'us-ascii'
    chunks = []
    expect = 0
    for i in sorted(segs, key=str):
        if i != expect:
            break
        enc, v = segs[i]
        if enc and i == 0:
            charset, _, rest = v.partition("'")
            _, _, v = rest.partition("'")
        chunks.append(unquote_to_bytes(v) if enc else v.encode('latin-1', 'replace'))
        expect += 1
    return b''.join(chunks).decode(codec(charset), 'replace')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short1']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a1'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a1b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b1'], ['filename*01', 'X']],), 'ab1'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_1.txt']],), 'café_1.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine1']],), "it'sfine1"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve1.txt"], ['filename*0', 'seg']],), 'naïve1.txt'), ('orphan continuation', ([['filename', 'plain1.txt'], ['filename*1', 'orphan']],), 'plain1.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per1']],), 'upper1')], 2: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short2']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a2'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a2b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b2'], ['filename*01', 'X']],), 'ab2'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_2.txt']],), 'café_2.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine2']],), "it'sfine2"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve2.txt"], ['filename*0', 'seg']],), 'naïve2.txt'), ('orphan continuation', ([['filename', 'plain2.txt'], ['filename*1', 'orphan']],), 'plain2.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per2']],), 'upper2')], 3: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short3']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a3'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a3b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b3'], ['filename*01', 'X']],), 'ab3'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_3.txt']],), 'café_3.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine3']],), "it'sfine3"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve3.txt"], ['filename*0', 'seg']],), 'naïve3.txt'), ('orphan continuation', ([['filename', 'plain3.txt'], ['filename*1', 'orphan']],), 'plain3.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per3']],), 'upper3')], 4: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short4']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a4'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a4b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b4'], ['filename*01', 'X']],), 'ab4'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_4.txt']],), 'café_4.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine4']],), "it'sfine4"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve4.txt"], ['filename*0', 'seg']],), 'naïve4.txt'), ('orphan continuation', ([['filename', 'plain4.txt'], ['filename*1', 'orphan']],), 'plain4.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per4']],), 'upper4')], 5: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short5']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a5'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a5b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b5'], ['filename*01', 'X']],), 'ab5'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_5.txt']],), 'café_5.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine5']],), "it'sfine5"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve5.txt"], ['filename*0', 'seg']],), 'naïve5.txt'), ('orphan continuation', ([['filename', 'plain5.txt'], ['filename*1', 'orphan']],), 'plain5.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per5']],), 'upper5')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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)

meaning: Fixture-count band, not measured model difficulty

deps: stdlib

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from urllib.parse import unquote_to_bytes
N = 1
observations = []
def solve(params):
    single = None
    plain = None
    segs = {}
    for name, value in params:
        n = name.lower()
        if n == 'filename*':
            single = value
        elif n == 'filename':
            plain = value
        elif n.startswith('filename*'):
            rest = n[9:]
            enc = rest.endswith('*')
            num = rest[:-1] if enc else rest
            if num.isdigit() and (num == '0' or not num.startswith('0')):
                segs[int(num)] = (enc, value)
    def codec(cs):
        cs = (cs or 'us-ascii').lower()
        return cs if cs in ('utf-8', 'iso-8859-1', 'us-ascii') else 'utf-8'
    if single is not None:
        cs, _, rest = single.partition("'")
        _, _, value = rest.partition("'")
        return unquote_to_bytes(value).decode(codec(cs), 'replace')
    if 0 not in segs:
        return plain
    charset = 'us-ascii'
    chunks = []
    expect = 0
    for i in list(segs):
        if i != expect:
            break
        enc, v = segs[i]
        if enc and i == 0:
            charset, _, rest = v.partition("'")
            _, _, v = rest.partition("'")
        chunks.append(unquote_to_bytes(v) if enc else v.encode('latin-1', 'replace'))
        expect += 1
    return b''.join(chunks).decode(codec(charset), 'replace')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short1']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a1'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a1b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b1'], ['filename*01', 'X']],), 'ab1'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_1.txt']],), 'café_1.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine1']],), "it'sfine1"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve1.txt"], ['filename*0', 'seg']],), 'naïve1.txt'), ('orphan continuation', ([['filename', 'plain1.txt'], ['filename*1', 'orphan']],), 'plain1.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per1']],), 'upper1')], 2: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short2']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a2'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a2b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b2'], ['filename*01', 'X']],), 'ab2'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_2.txt']],), 'café_2.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine2']],), "it'sfine2"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve2.txt"], ['filename*0', 'seg']],), 'naïve2.txt'), ('orphan continuation', ([['filename', 'plain2.txt'], ['filename*1', 'orphan']],), 'plain2.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per2']],), 'upper2')], 3: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short3']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a3'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a3b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b3'], ['filename*01', 'X']],), 'ab3'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_3.txt']],), 'café_3.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine3']],), "it'sfine3"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve3.txt"], ['filename*0', 'seg']],), 'naïve3.txt'), ('orphan continuation', ([['filename', 'plain3.txt'], ['filename*1', 'orphan']],), 'plain3.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per3']],), 'upper3')], 4: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short4']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a4'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a4b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b4'], ['filename*01', 'X']],), 'ab4'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_4.txt']],), 'café_4.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine4']],), "it'sfine4"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve4.txt"], ['filename*0', 'seg']],), 'naïve4.txt'), ('orphan continuation', ([['filename', 'plain4.txt'], ['filename*1', 'orphan']],), 'plain4.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per4']],), 'upper4')], 5: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short5']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a5'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a5b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b5'], ['filename*01', 'X']],), 'ab5'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_5.txt']],), 'café_5.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine5']],), "it'sfine5"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve5.txt"], ['filename*0', 'seg']],), 'naïve5.txt'), ('orphan continuation', ([['filename', 'plain5.txt'], ['filename*1', 'orphan']],), 'plain5.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per5']],), 'upper5')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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)

prompt:
Names with ten or more continuation segments are cut after segment 1 because "10" sorts before "2".

params are [name, value] pairs; names are case-insensitive. "filename*" (a single extended value charset'lang'text) wins over everything. Otherwise segments "filename*<n>" (plain) and "filename*<n>*" (percent-encoded) with decimal n without leading zeros ("0" allowed) are joined in numeric order from 0, stopping at the first gap; only an encoded segment 0 carries the charset'lang' prefix. Bytes of all segments are concatenated before decoding with the charset (utf-8, iso-8859-1 or us-ascii; others decode as utf-8; undecodable bytes become U+FFFD). Without a segment 0 the plain "filename" value (or None) is returned.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from urllib.parse import unquote_to_bytes
N = 1
observations = []
def solve(params):
    single = None
    plain = None
    segs = {}
    for name, value in params:
        n = name.lower()
        if n == 'filename*':
            single = value
        elif n == 'filename':
            plain = value
        elif n.startswith('filename*'):
            rest = n[9:]
            enc = rest.endswith('*')
            num = rest[:-1] if enc else rest
            if num.isdigit() and (num == '0' or not num.startswith('0')):
                segs[int(num)] = (enc, value)
    def codec(cs):
        cs = (cs or 'us-ascii').lower()
        return cs if cs in ('utf-8', 'iso-8859-1', 'us-ascii') else 'utf-8'
    if single is not None:
        cs, _, rest = single.partition("'")
        _, _, value = rest.partition("'")
        return unquote_to_bytes(value).decode(codec(cs), 'replace')
    if 0 not in segs:
        return plain
    charset = 'us-ascii'
    chunks = []
    expect = 0
    for i in sorted(segs):
        if i < expect:
            continue
        enc, v = segs[i]
        if enc and i == 0:
            charset, _, rest = v.partition("'")
            _, _, v = rest.partition("'")
        chunks.append(unquote_to_bytes(v) if enc else v.encode('latin-1', 'replace'))
        expect += 1
    return b''.join(chunks).decode(codec(charset), 'replace')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short1']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a1'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a1b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b1'], ['filename*01', 'X']],), 'ab1'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_1.txt']],), 'café_1.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine1']],), "it'sfine1"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve1.txt"], ['filename*0', 'seg']],), 'naïve1.txt'), ('orphan continuation', ([['filename', 'plain1.txt'], ['filename*1', 'orphan']],), 'plain1.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per1']],), 'upper1')], 2: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short2']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a2'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a2b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b2'], ['filename*01', 'X']],), 'ab2'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_2.txt']],), 'café_2.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine2']],), "it'sfine2"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve2.txt"], ['filename*0', 'seg']],), 'naïve2.txt'), ('orphan continuation', ([['filename', 'plain2.txt'], ['filename*1', 'orphan']],), 'plain2.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per2']],), 'upper2')], 3: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short3']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a3'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a3b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b3'], ['filename*01', 'X']],), 'ab3'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_3.txt']],), 'café_3.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine3']],), "it'sfine3"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve3.txt"], ['filename*0', 'seg']],), 'naïve3.txt'), ('orphan continuation', ([['filename', 'plain3.txt'], ['filename*1', 'orphan']],), 'plain3.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per3']],), 'upper3')], 4: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short4']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a4'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a4b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b4'], ['filename*01', 'X']],), 'ab4'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_4.txt']],), 'café_4.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine4']],), "it'sfine4"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve4.txt"], ['filename*0', 'seg']],), 'naïve4.txt'), ('orphan continuation', ([['filename', 'plain4.txt'], ['filename*1', 'orphan']],), 'plain4.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per4']],), 'upper4')], 5: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short5']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a5'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a5b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b5'], ['filename*01', 'X']],), 'ab5'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_5.txt']],), 'café_5.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine5']],), "it'sfine5"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve5.txt"], ['filename*0', 'seg']],), 'naïve5.txt'), ('orphan continuation', ([['filename', 'plain5.txt'], ['filename*1', 'orphan']],), 'plain5.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per5']],), 'upper5')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from urllib.parse import unquote_to_bytes
N = 1
observations = []
def solve(params):
    single = None
    plain = None
    segs = {}
    for name, value in params:
        n = name.lower()
        if n == 'filename*':
            single = value
        elif n == 'filename':
            plain = value
        elif n.startswith('filename*'):
            rest = n[9:]
            enc = rest.endswith('*')
            num = rest[:-1] if enc else rest
            if num.isdigit() and (num == '0' or not num.startswith('0')):
                segs[int(num)] = (enc, value)
    def codec(cs):
        cs = (cs or 'us-ascii').lower()
        return cs if cs in ('utf-8', 'iso-8859-1', 'us-ascii') else 'utf-8'
    if single is not None:
        cs, _, rest = single.partition("'")
        _, _, value = rest.partition("'")
        return unquote_to_bytes(value).decode(codec(cs), 'replace')
    if 0 not in segs:
        return plain
    charset = 'us-ascii'
    chunks = []
    expect = 0
    for i in sorted(segs):
        if i > expect + 1:
            break
        enc, v = segs[i]
        if enc and i == 0:
            charset, _, rest = v.partition("'")
            _, _, v = rest.partition("'")
        chunks.append(unquote_to_bytes(v) if enc else v.encode('latin-1', 'replace'))
        expect += 1
    return b''.join(chunks).decode(codec(charset), 'replace')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short1']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a1'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a1b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b1'], ['filename*01', 'X']],), 'ab1'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_1.txt']],), 'café_1.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine1']],), "it'sfine1"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve1.txt"], ['filename*0', 'seg']],), 'naïve1.txt'), ('orphan continuation', ([['filename', 'plain1.txt'], ['filename*1', 'orphan']],), 'plain1.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per1']],), 'upper1')], 2: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short2']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a2'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a2b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b2'], ['filename*01', 'X']],), 'ab2'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_2.txt']],), 'café_2.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine2']],), "it'sfine2"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve2.txt"], ['filename*0', 'seg']],), 'naïve2.txt'), ('orphan continuation', ([['filename', 'plain2.txt'], ['filename*1', 'orphan']],), 'plain2.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per2']],), 'upper2')], 3: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short3']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a3'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a3b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b3'], ['filename*01', 'X']],), 'ab3'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_3.txt']],), 'café_3.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine3']],), "it'sfine3"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve3.txt"], ['filename*0', 'seg']],), 'naïve3.txt'), ('orphan continuation', ([['filename', 'plain3.txt'], ['filename*1', 'orphan']],), 'plain3.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per3']],), 'upper3')], 4: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short4']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a4'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a4b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b4'], ['filename*01', 'X']],), 'ab4'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_4.txt']],), 'café_4.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine4']],), "it'sfine4"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve4.txt"], ['filename*0', 'seg']],), 'naïve4.txt'), ('orphan continuation', ([['filename', 'plain4.txt'], ['filename*1', 'orphan']],), 'plain4.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per4']],), 'upper4')], 5: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short5']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a5'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a5b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b5'], ['filename*01', 'X']],), 'ab5'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_5.txt']],), 'café_5.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine5']],), "it'sfine5"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve5.txt"], ['filename*0', 'seg']],), 'naïve5.txt'), ('orphan continuation', ([['filename', 'plain5.txt'], ['filename*1', 'orphan']],), 'plain5.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per5']],), 'upper5')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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)

prompt:
Segments after a missing index are glued on, producing a name that was never sent.

params are [name, value] pairs; names are case-insensitive. "filename*" (a single extended value charset'lang'text) wins over everything. Otherwise segments "filename*<n>" (plain) and "filename*<n>*" (percent-encoded) with decimal n without leading zeros ("0" allowed) are joined in numeric order from 0, stopping at the first gap; only an encoded segment 0 carries the charset'lang' prefix. Bytes of all segments are concatenated before decoding with the charset (utf-8, iso-8859-1 or us-ascii; others decode as utf-8; undecodable bytes become U+FFFD). Without a segment 0 the plain "filename" value (or None) is returned.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from urllib.parse import unquote_to_bytes
N = 1
observations = []
def solve(params):
    single = None
    plain = None
    segs = {}
    for name, value in params:
        n = name.lower()
        if n == 'filename*':
            single = value
        elif n == 'filename':
            plain = value
        elif n.startswith('filename*'):
            rest = n[9:]
            enc = rest.endswith('*')
            num = rest[:-1] if enc else rest
            if num.isdigit():
                segs[int(num)] = (enc, value)
    def codec(cs):
        cs = (cs or 'us-ascii').lower()
        return cs if cs in ('utf-8', 'iso-8859-1', 'us-ascii') else 'utf-8'
    if single is not None:
        cs, _, rest = single.partition("'")
        _, _, value = rest.partition("'")
        return unquote_to_bytes(value).decode(codec(cs), 'replace')
    if 0 not in segs:
        return plain
    charset = 'us-ascii'
    chunks = []
    expect = 0
    for i in sorted(segs):
        if i != expect:
            break
        enc, v = segs[i]
        if enc and i == 0:
            charset, _, rest = v.partition("'")
            _, _, v = rest.partition("'")
        chunks.append(unquote_to_bytes(v) if enc else v.encode('latin-1', 'replace'))
        expect += 1
    return b''.join(chunks).decode(codec(charset), 'replace')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short1']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a1'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a1b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b1'], ['filename*01', 'X']],), 'ab1'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_1.txt']],), 'café_1.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine1']],), "it'sfine1"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve1.txt"], ['filename*0', 'seg']],), 'naïve1.txt'), ('orphan continuation', ([['filename', 'plain1.txt'], ['filename*1', 'orphan']],), 'plain1.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per1']],), 'upper1')], 2: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short2']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a2'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a2b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b2'], ['filename*01', 'X']],), 'ab2'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_2.txt']],), 'café_2.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine2']],), "it'sfine2"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve2.txt"], ['filename*0', 'seg']],), 'naïve2.txt'), ('orphan continuation', ([['filename', 'plain2.txt'], ['filename*1', 'orphan']],), 'plain2.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per2']],), 'upper2')], 3: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short3']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a3'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a3b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b3'], ['filename*01', 'X']],), 'ab3'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_3.txt']],), 'café_3.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine3']],), "it'sfine3"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve3.txt"], ['filename*0', 'seg']],), 'naïve3.txt'), ('orphan continuation', ([['filename', 'plain3.txt'], ['filename*1', 'orphan']],), 'plain3.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per3']],), 'upper3')], 4: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short4']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a4'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a4b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b4'], ['filename*01', 'X']],), 'ab4'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_4.txt']],), 'café_4.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine4']],), "it'sfine4"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve4.txt"], ['filename*0', 'seg']],), 'naïve4.txt'), ('orphan continuation', ([['filename', 'plain4.txt'], ['filename*1', 'orphan']],), 'plain4.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per4']],), 'upper4')], 5: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short5']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a5'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a5b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b5'], ['filename*01', 'X']],), 'ab5'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_5.txt']],), 'café_5.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine5']],), "it'sfine5"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve5.txt"], ['filename*0', 'seg']],), 'naïve5.txt'), ('orphan continuation', ([['filename', 'plain5.txt'], ['filename*1', 'orphan']],), 'plain5.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per5']],), 'upper5')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from urllib.parse import unquote_to_bytes
N = 1
observations = []
def solve(params):
    single = None
    plain = None
    segs = {}
    for name, value in params:
        n = name.lower()
        if n == 'filename*':
            single = value
        elif n == 'filename':
            plain = value
        elif n.startswith('filename*'):
            rest = n[9:]
            enc = rest.endswith('*')
            num = rest[:-1] if enc else rest
            if num.isdigit() and not num.startswith('00'):
                segs[int(num)] = (enc, value)
    def codec(cs):
        cs = (cs or 'us-ascii').lower()
        return cs if cs in ('utf-8', 'iso-8859-1', 'us-ascii') else 'utf-8'
    if single is not None:
        cs, _, rest = single.partition("'")
        _, _, value = rest.partition("'")
        return unquote_to_bytes(value).decode(codec(cs), 'replace')
    if 0 not in segs:
        return plain
    charset = 'us-ascii'
    chunks = []
    expect = 0
    for i in sorted(segs):
        if i != expect:
            break
        enc, v = segs[i]
        if enc and i == 0:
            charset, _, rest = v.partition("'")
            _, _, v = rest.partition("'")
        chunks.append(unquote_to_bytes(v) if enc else v.encode('latin-1', 'replace'))
        expect += 1
    return b''.join(chunks).decode(codec(charset), 'replace')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short1']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a1'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a1b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b1'], ['filename*01', 'X']],), 'ab1'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_1.txt']],), 'café_1.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine1']],), "it'sfine1"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve1.txt"], ['filename*0', 'seg']],), 'naïve1.txt'), ('orphan continuation', ([['filename', 'plain1.txt'], ['filename*1', 'orphan']],), 'plain1.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per1']],), 'upper1')], 2: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short2']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a2'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a2b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b2'], ['filename*01', 'X']],), 'ab2'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_2.txt']],), 'café_2.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine2']],), "it'sfine2"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve2.txt"], ['filename*0', 'seg']],), 'naïve2.txt'), ('orphan continuation', ([['filename', 'plain2.txt'], ['filename*1', 'orphan']],), 'plain2.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per2']],), 'upper2')], 3: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short3']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a3'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a3b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b3'], ['filename*01', 'X']],), 'ab3'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_3.txt']],), 'café_3.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine3']],), "it'sfine3"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve3.txt"], ['filename*0', 'seg']],), 'naïve3.txt'), ('orphan continuation', ([['filename', 'plain3.txt'], ['filename*1', 'orphan']],), 'plain3.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per3']],), 'upper3')], 4: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short4']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a4'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a4b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b4'], ['filename*01', 'X']],), 'ab4'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_4.txt']],), 'café_4.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine4']],), "it'sfine4"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve4.txt"], ['filename*0', 'seg']],), 'naïve4.txt'), ('orphan continuation', ([['filename', 'plain4.txt'], ['filename*1', 'orphan']],), 'plain4.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per4']],), 'upper4')], 5: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short5']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a5'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a5b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b5'], ['filename*01', 'X']],), 'ab5'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_5.txt']],), 'café_5.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine5']],), "it'sfine5"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve5.txt"], ['filename*0', 'seg']],), 'naïve5.txt'), ('orphan continuation', ([['filename', 'plain5.txt'], ['filename*1', 'orphan']],), 'plain5.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per5']],), 'upper5')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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)

prompt:
A segment numbered "01" overwrites segment 1.

params are [name, value] pairs; names are case-insensitive. "filename*" (a single extended value charset'lang'text) wins over everything. Otherwise segments "filename*<n>" (plain) and "filename*<n>*" (percent-encoded) with decimal n without leading zeros ("0" allowed) are joined in numeric order from 0, stopping at the first gap; only an encoded segment 0 carries the charset'lang' prefix. Bytes of all segments are concatenated before decoding with the charset (utf-8, iso-8859-1 or us-ascii; others decode as utf-8; undecodable bytes become U+FFFD). Without a segment 0 the plain "filename" value (or None) is returned.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from urllib.parse import unquote_to_bytes
N = 1
observations = []
def solve(params):
    single = None
    plain = None
    segs = {}
    for name, value in params:
        n = name.lower()
        if n == 'filename*':
            single = value
        elif n == 'filename':
            plain = value
        elif n.startswith('filename*'):
            rest = n[9:]
            enc = rest.endswith('*')
            num = rest[:-1] if enc else rest
            if num.isdigit() and (num == '0' or not num.startswith('0')):
                segs[int(num)] = (enc, value)
    def codec(cs):
        cs = (cs or 'us-ascii').lower()
        return cs if cs in ('utf-8', 'iso-8859-1', 'us-ascii') else 'utf-8'
    if single is not None:
        cs, _, rest = single.partition("'")
        _, _, value = rest.partition("'")
        return unquote_to_bytes(value).decode(codec(cs), 'replace')
    if 0 not in segs:
        return plain
    charset = 'us-ascii'
    chunks = []
    expect = 0
    for i in sorted(segs):
        if i != expect:
            break
        enc, v = segs[i]
        if enc:
            charset, _, rest = v.partition("'")
            _, _, v = rest.partition("'")
        chunks.append(unquote_to_bytes(v) if enc else v.encode('latin-1', 'replace'))
        expect += 1
    return b''.join(chunks).decode(codec(charset), 'replace')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short1']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a1'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a1b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b1'], ['filename*01', 'X']],), 'ab1'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_1.txt']],), 'café_1.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine1']],), "it'sfine1"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve1.txt"], ['filename*0', 'seg']],), 'naïve1.txt'), ('orphan continuation', ([['filename', 'plain1.txt'], ['filename*1', 'orphan']],), 'plain1.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per1']],), 'upper1')], 2: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short2']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a2'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a2b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b2'], ['filename*01', 'X']],), 'ab2'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_2.txt']],), 'café_2.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine2']],), "it'sfine2"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve2.txt"], ['filename*0', 'seg']],), 'naïve2.txt'), ('orphan continuation', ([['filename', 'plain2.txt'], ['filename*1', 'orphan']],), 'plain2.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per2']],), 'upper2')], 3: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short3']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a3'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a3b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b3'], ['filename*01', 'X']],), 'ab3'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_3.txt']],), 'café_3.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine3']],), "it'sfine3"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve3.txt"], ['filename*0', 'seg']],), 'naïve3.txt'), ('orphan continuation', ([['filename', 'plain3.txt'], ['filename*1', 'orphan']],), 'plain3.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per3']],), 'upper3')], 4: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short4']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a4'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a4b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b4'], ['filename*01', 'X']],), 'ab4'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_4.txt']],), 'café_4.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine4']],), "it'sfine4"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve4.txt"], ['filename*0', 'seg']],), 'naïve4.txt'), ('orphan continuation', ([['filename', 'plain4.txt'], ['filename*1', 'orphan']],), 'plain4.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per4']],), 'upper4')], 5: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short5']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a5'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a5b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b5'], ['filename*01', 'X']],), 'ab5'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_5.txt']],), 'café_5.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine5']],), "it'sfine5"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve5.txt"], ['filename*0', 'seg']],), 'naïve5.txt'), ('orphan continuation', ([['filename', 'plain5.txt'], ['filename*1', 'orphan']],), 'plain5.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per5']],), 'upper5')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from urllib.parse import unquote_to_bytes
N = 1
observations = []
def solve(params):
    single = None
    plain = None
    segs = {}
    for name, value in params:
        n = name.lower()
        if n == 'filename*':
            single = value
        elif n == 'filename':
            plain = value
        elif n.startswith('filename*'):
            rest = n[9:]
            enc = rest.endswith('*')
            num = rest[:-1] if enc else rest
            if num.isdigit() and (num == '0' or not num.startswith('0')):
                segs[int(num)] = (enc, value)
    def codec(cs):
        cs = (cs or 'us-ascii').lower()
        return cs if cs in ('utf-8', 'iso-8859-1', 'us-ascii') else 'utf-8'
    if single is not None:
        cs, _, rest = single.partition("'")
        _, _, value = rest.partition("'")
        return unquote_to_bytes(value).decode(codec(cs), 'replace')
    if 0 not in segs:
        return plain
    charset = 'us-ascii'
    chunks = []
    expect = 0
    for i in sorted(segs):
        if i != expect:
            break
        enc, v = segs[i]
        if i == 0:
            charset, _, rest = v.partition("'")
            _, _, v = rest.partition("'")
        chunks.append(unquote_to_bytes(v) if enc else v.encode('latin-1', 'replace'))
        expect += 1
    return b''.join(chunks).decode(codec(charset), 'replace')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short1']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a1'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a1b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b1'], ['filename*01', 'X']],), 'ab1'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_1.txt']],), 'café_1.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine1']],), "it'sfine1"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve1.txt"], ['filename*0', 'seg']],), 'naïve1.txt'), ('orphan continuation', ([['filename', 'plain1.txt'], ['filename*1', 'orphan']],), 'plain1.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per1']],), 'upper1')], 2: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short2']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a2'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a2b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b2'], ['filename*01', 'X']],), 'ab2'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_2.txt']],), 'café_2.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine2']],), "it'sfine2"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve2.txt"], ['filename*0', 'seg']],), 'naïve2.txt'), ('orphan continuation', ([['filename', 'plain2.txt'], ['filename*1', 'orphan']],), 'plain2.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per2']],), 'upper2')], 3: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short3']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a3'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a3b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b3'], ['filename*01', 'X']],), 'ab3'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_3.txt']],), 'café_3.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine3']],), "it'sfine3"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve3.txt"], ['filename*0', 'seg']],), 'naïve3.txt'), ('orphan continuation', ([['filename', 'plain3.txt'], ['filename*1', 'orphan']],), 'plain3.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per3']],), 'upper3')], 4: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short4']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a4'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a4b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b4'], ['filename*01', 'X']],), 'ab4'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_4.txt']],), 'café_4.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine4']],), "it'sfine4"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve4.txt"], ['filename*0', 'seg']],), 'naïve4.txt'), ('orphan continuation', ([['filename', 'plain4.txt'], ['filename*1', 'orphan']],), 'plain4.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per4']],), 'upper4')], 5: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short5']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a5'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a5b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b5'], ['filename*01', 'X']],), 'ab5'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_5.txt']],), 'café_5.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine5']],), "it'sfine5"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve5.txt"], ['filename*0', 'seg']],), 'naïve5.txt'), ('orphan continuation', ([['filename', 'plain5.txt'], ['filename*1', 'orphan']],), 'plain5.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per5']],), 'upper5')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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)

prompt:
Later encoded segments are parsed as if they carried a charset prefix and lose their text.

params are [name, value] pairs; names are case-insensitive. "filename*" (a single extended value charset'lang'text) wins over everything. Otherwise segments "filename*<n>" (plain) and "filename*<n>*" (percent-encoded) with decimal n without leading zeros ("0" allowed) are joined in numeric order from 0, stopping at the first gap; only an encoded segment 0 carries the charset'lang' prefix. Bytes of all segments are concatenated before decoding with the charset (utf-8, iso-8859-1 or us-ascii; others decode as utf-8; undecodable bytes become U+FFFD). Without a segment 0 the plain "filename" value (or None) is returned.

split: open-access


broken_source:
"""Failure Map reference implementation. Python standard library only."""
import json
from urllib.parse import unquote_to_bytes
N = 1
observations = []
def solve(params):
    single = None
    plain = None
    segs = {}
    for name, value in params:
        n = name.lower()
        if n == 'filename*':
            single = value
        elif n == 'filename':
            plain = value
        elif n.startswith('filename*'):
            rest = n[9:]
            enc = rest.endswith('*')
            num = rest[:-1] if enc else rest
            if num.isdigit() and (num == '0' or not num.startswith('0')):
                segs[int(num)] = (enc, value)
    def codec(cs):
        cs = (cs or 'us-ascii').lower()
        return cs if cs in ('utf-8', 'iso-8859-1', 'us-ascii') else 'utf-8'
    if single is not None and 0 not in segs:
        cs, _, rest = single.partition("'")
        _, _, value = rest.partition("'")
        return unquote_to_bytes(value).decode(codec(cs), 'replace')
    if 0 not in segs:
        return plain
    charset = 'us-ascii'
    chunks = []
    expect = 0
    for i in sorted(segs):
        if i != expect:
            break
        enc, v = segs[i]
        if enc and i == 0:
            charset, _, rest = v.partition("'")
            _, _, v = rest.partition("'")
        chunks.append(unquote_to_bytes(v) if enc else v.encode('latin-1', 'replace'))
        expect += 1
    return b''.join(chunks).decode(codec(charset), 'replace')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short1']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a1'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a1b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b1'], ['filename*01', 'X']],), 'ab1'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_1.txt']],), 'café_1.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine1']],), "it'sfine1"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve1.txt"], ['filename*0', 'seg']],), 'naïve1.txt'), ('orphan continuation', ([['filename', 'plain1.txt'], ['filename*1', 'orphan']],), 'plain1.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per1']],), 'upper1')], 2: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short2']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a2'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a2b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b2'], ['filename*01', 'X']],), 'ab2'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_2.txt']],), 'café_2.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine2']],), "it'sfine2"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve2.txt"], ['filename*0', 'seg']],), 'naïve2.txt'), ('orphan continuation', ([['filename', 'plain2.txt'], ['filename*1', 'orphan']],), 'plain2.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per2']],), 'upper2')], 3: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short3']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a3'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a3b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b3'], ['filename*01', 'X']],), 'ab3'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_3.txt']],), 'café_3.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine3']],), "it'sfine3"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve3.txt"], ['filename*0', 'seg']],), 'naïve3.txt'), ('orphan continuation', ([['filename', 'plain3.txt'], ['filename*1', 'orphan']],), 'plain3.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per3']],), 'upper3')], 4: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short4']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a4'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a4b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b4'], ['filename*01', 'X']],), 'ab4'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_4.txt']],), 'café_4.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine4']],), "it'sfine4"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve4.txt"], ['filename*0', 'seg']],), 'naïve4.txt'), ('orphan continuation', ([['filename', 'plain4.txt'], ['filename*1', 'orphan']],), 'plain4.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per4']],), 'upper4')], 5: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short5']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a5'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a5b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b5'], ['filename*01', 'X']],), 'ab5'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_5.txt']],), 'café_5.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine5']],), "it'sfine5"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve5.txt"], ['filename*0', 'seg']],), 'naïve5.txt'), ('orphan continuation', ([['filename', 'plain5.txt'], ['filename*1', 'orphan']],), 'plain5.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per5']],), 'upper5')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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)

source:
"""Failure Map reference implementation. Python standard library only."""
import json
from urllib.parse import unquote_to_bytes
N = 1
observations = []
def solve(params):
    single = None
    plain = None
    segs = {}
    for name, value in params:
        n = name.lower()
        if n == 'filename*':
            single = value
        elif n == 'filename':
            plain = value
        elif n.startswith('filename*'):
            rest = n[9:]
            enc = rest.endswith('*')
            num = rest[:-1] if enc else rest
            if num.isdigit() and (num == '0' or not num.startswith('0')):
                segs[int(num)] = (enc, value)
    def codec(cs):
        cs = (cs or 'us-ascii').lower()
        return cs if cs in ('utf-8', 'iso-8859-1', 'us-ascii') else 'utf-8'
    if single is not None and plain is None:
        cs, _, rest = single.partition("'")
        _, _, value = rest.partition("'")
        return unquote_to_bytes(value).decode(codec(cs), 'replace')
    if 0 not in segs:
        return plain
    charset = 'us-ascii'
    chunks = []
    expect = 0
    for i in sorted(segs):
        if i != expect:
            break
        enc, v = segs[i]
        if enc and i == 0:
            charset, _, rest = v.partition("'")
            _, _, v = rest.partition("'")
        chunks.append(unquote_to_bytes(v) if enc else v.encode('latin-1', 'replace'))
        expect += 1
    return b''.join(chunks).decode(codec(charset), 'replace')
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
_CASES = {1: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short1']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a1'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a1b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b1'], ['filename*01', 'X']],), 'ab1'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_1.txt']],), 'café_1.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine1']],), "it'sfine1"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve1.txt"], ['filename*0', 'seg']],), 'naïve1.txt'), ('orphan continuation', ([['filename', 'plain1.txt'], ['filename*1', 'orphan']],), 'plain1.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per1']],), 'upper1')], 2: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short2']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a2'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a2b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b2'], ['filename*01', 'X']],), 'ab2'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_2.txt']],), 'café_2.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine2']],), "it'sfine2"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve2.txt"], ['filename*0', 'seg']],), 'naïve2.txt'), ('orphan continuation', ([['filename', 'plain2.txt'], ['filename*1', 'orphan']],), 'plain2.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per2']],), 'upper2')], 3: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short3']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a3'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a3b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b3'], ['filename*01', 'X']],), 'ab3'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_3.txt']],), 'café_3.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine3']],), "it'sfine3"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve3.txt"], ['filename*0', 'seg']],), 'naïve3.txt'), ('orphan continuation', ([['filename', 'plain3.txt'], ['filename*1', 'orphan']],), 'plain3.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per3']],), 'upper3')], 4: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short4']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a4'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a4b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b4'], ['filename*01', 'X']],), 'ab4'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_4.txt']],), 'café_4.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine4']],), "it'sfine4"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve4.txt"], ['filename*0', 'seg']],), 'naïve4.txt'), ('orphan continuation', ([['filename', 'plain4.txt'], ['filename*1', 'orphan']],), 'plain4.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per4']],), 'upper4')], 5: [('twelve segments', ([['filename*0', 'p0.'], ['filename*1', 'p1.'], ['filename*10', 'p10.'], ['filename*11', 'p11.'], ['filename*2', 'p2.'], ['filename*3', 'p3.'], ['filename*4', 'p4.'], ['filename*5', 'p5.'], ['filename*6', 'p6.'], ['filename*7', 'p7.'], ['filename*8', 'p8.'], ['filename*9', 'p9.'], ['filename', 'short5']],), 'p0.p1.p2.p3.p4.p5.p6.p7.p8.p9.p10.p11.'), ('gap in segments', ([['filename*0', 'a5'], ['filename*1', 'b'], ['filename*3', 'd']],), 'a5b'), ('leading zero index', ([['filename*0', 'a'], ['filename*1', 'b5'], ['filename*01', 'X']],), 'ab5'), ('charset only on first segment', ([['filename*0*', "utf-8''caf%C3"], ['filename*1*', '%A9_5.txt']],), 'café_5.txt'), ('quote inside plain first segment', ([['filename*0', "it's"], ['filename*1', 'fine5']],), "it'sfine5"), ('single extended value wins', ([['filename', 'plain.txt'], ['filename*', "utf-8''na%C3%AFve5.txt"], ['filename*0', 'seg']],), 'naïve5.txt'), ('orphan continuation', ([['filename', 'plain5.txt'], ['filename*1', 'orphan']],), 'plain5.txt'), ('upper-case names', ([['FileName*0', 'up'], ['FILENAME*1', 'per5']],), 'upper5')]}
for _label, _args, _expected in _CASES[N]:
    check(_label, solve(*_args), _expected)
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)

prompt:
Continuation segments override a complete filename* value.

params are [name, value] pairs; names are case-insensitive. "filename*" (a single extended value charset'lang'text) wins over everything. Otherwise segments "filename*<n>" (plain) and "filename*<n>*" (percent-encoded) with decimal n without leading zeros ("0" allowed) are joined in numeric order from 0, stopping at the first gap; only an encoded segment 0 carries the charset'lang' prefix. Bytes of all segments are concatenated before decoding with the charset (utf-8, iso-8859-1 or us-ascii; others decode as utf-8; undecodable bytes become U+FFFD). Without a segment 0 the plain "filename" value (or None) is returned.

split: open-access