{"record":{"id":"8f35d1b77850bd25","repo":"larksuite/cli","slug":"unsupported-complemented-xsd-character-class-esc","errorCode":null,"errorMessage":"unsupported complemented XSD character class \\{escaped} inside []","messagePattern":"unsupported complemented XSD character class \\\\(.+?) inside \\[\\]","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"skills/lark-slides/scripts/sxsd_validator.py","lineNumber":549,"sourceCode":"        return scalar_value_for_type(rule.base, value, model, resolving)\n    finally:\n        resolving.remove(type_name)\n\n\n@lru_cache(maxsize=32)\ndef python_pattern_for_xsd(pattern: str) -> str:\n    translated: list[str] = []\n    in_character_class = False\n    index = 0\n    while index < len(pattern):\n        char = pattern[index]\n        if char == \"\\\\\" and index + 1 < len(pattern):\n            escaped = pattern[index + 1]\n            if escaped in {\"s\", \"S\"}:\n                body = r\" \\t\\n\\r\"\n                if in_character_class:\n                    if escaped == \"S\":\n                        raise ValueError(\n                            f\"unsupported complemented XSD character class \\\\{escaped} inside []\"\n                        )\n                    translated.append(body)\n                else:\n                    prefix = \"^\" if escaped == \"S\" else \"\"\n                    translated.append(f\"[{prefix}{body}]\")\n                index += 2\n                continue\n            translated.extend((char, escaped))\n            index += 2\n            continue\n        if char == \"[\":\n            in_character_class = True\n        elif char == \"]\":\n            in_character_class = False\n        elif char == \".\" and not in_character_class:\n            translated.append(r\"[^\\n\\r]\")\n            index += 1","sourceCodeStart":531,"sourceCodeEnd":567,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/skills/lark-slides/scripts/sxsd_validator.py#L531-L567","documentation":"python_pattern_for_xsd translates XSD regex character shortcuts to Python regex. Inside a bracketed character class, \\S (complemented whitespace class) cannot be expressed in the validator's translation, so it raises this ValueError. Outside a class, \\S becomes [^ \\t\\n\\r], but inside [] the negated form would change class semantics unsafely, so the validator refuses rather than produce a wrong pattern.","triggerScenarios":"Validating an XSD pattern facet (via xsd_pattern_matches) whose pattern contains \\S inside square brackets, e.g. pattern=\"[\\S]+\" or \"[a-z\\S]\".","commonSituations":"Schemas written with XSD-flavored regex shortcuts; schema authors assuming \\S works anywhere; patterns ported from XML Schema validators (like Xerces) that support \\S inside classes.","solutions":["Rewrite the pattern to avoid \\S inside [], e.g. use a negated outer class like [^ \\t\\n\\r] instead of [\\S].","Restructure the pattern so \\S appears outside the character class (e.g. '[a-z]\\\\S' if that matches intent).","Enumerate the allowed characters explicitly in the class.","If you control the schema, prefer patterns using only classes/escapes the validator supports."],"exampleFix":"// before\n<xsd:pattern value=\"[\\S]{4}\"/>\n// after\n<xsd:pattern value=\"[^ \\t\\n\\r]{4}\"/>","handlingStrategy":"try-catch","validationCode":"import re\n\ndef uses_complemented_class_shortcut(xsd_pattern):\n    # crude pre-check: \\S appearing inside an unclosed [ ... ] span\n    depth = 0\n    i = 0\n    while i < len(xsd_pattern):\n        if xsd_pattern[i] == '\\\\' and i + 1 < len(xsd_pattern):\n            if depth > 0 and xsd_pattern[i + 1] == 'S':\n                return True\n            i += 2\n            continue\n        if xsd_pattern[i] == '[':\n            depth += 1\n        elif xsd_pattern[i] == ']':\n            depth = max(0, depth - 1)\n        i += 1\n    return False","typeGuard":"def safe_xsd_pattern(p):\n    from functools import lru_cache\n    try:\n        python_pattern_for_xsd(p)\n        return p\n    except ValueError:\n        return None","tryCatchPattern":"try:\n    matches = xsd_pattern_matches(pattern, value)\nexcept ValueError as e:\n    print(f'rewrite schema pattern without \\\\S inside []: {e}')","preventionTips":["Prefer [^ \\t\\n\\r] over \\S inside character classes in XSD patterns.","Keep schema patterns to the common subset (classes, \\s, \\S outside classes).","Test pattern facets with the validator before shipping the schema."],"tags":["python","regex","xsd"],"backgroundTag":"unsupported-regex-construct","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}