{"id":"f82a6562df4dcfe1","repo":"pypa/pip","slug":"first-codepoint-in-label-label-r-must-be-directi","errorCode":null,"errorMessage":"First codepoint in label {label!r} must be directionality L, R or AL","messagePattern":"First codepoint in label (.+?) must be directionality L, R or AL","errorType":"validation","errorClass":"IDNABidiError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/idna/core.py","lineNumber":136,"sourceCode":"    bidi_label = False\n    for idx, cp in enumerate(label, 1):\n        direction = unicodedata.bidirectional(cp)\n        if direction == \"\":\n            # String likely comes from a newer version of Unicode\n            raise IDNABidiError(f\"Unknown directionality in label {label!r} at position {idx}\")\n        if direction in _bidi_rtl_categories:\n            bidi_label = True\n    if not bidi_label and not check_ltr:\n        return True\n\n    # Bidi rule 1\n    direction = unicodedata.bidirectional(label[0])\n    if direction in _bidi_rtl_first:\n        rtl = True\n    elif direction == \"L\":\n        rtl = False\n    else:\n        raise IDNABidiError(f\"First codepoint in label {label!r} must be directionality L, R or AL\")\n\n    valid_ending = False\n    number_type: Optional[str] = None\n    for idx, cp in enumerate(label, 1):\n        direction = unicodedata.bidirectional(cp)\n\n        if rtl:\n            # Bidi rule 2\n            if direction not in _bidi_rtl_allowed:\n                raise IDNABidiError(f\"Invalid direction for codepoint at position {idx} in a right-to-left label\")\n            # Bidi rule 3\n            if direction in _bidi_rtl_valid_ending:\n                valid_ending = True\n            elif direction != \"NSM\":\n                valid_ending = False\n            # Bidi rule 4\n            if direction in _bidi_rtl_numeric:\n                if not number_type:","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/idna/core.py#L118-L154","documentation":"IDNABidiError from check_bidi Bidi Rule 1: the first codepoint of a label under Bidi scrutiny must have bidirectional category L (left-to-right), R, or AL (Arabic letter). Any other leading category (e.g. ET, ON, NSM, EN) is rejected because RFC 5893 requires a strong directional start.","triggerScenarios":"A label starting with a digit, punctuation, combining mark, or European number while the label also contains RTL characters (forcing the Bidi check). Example: '1اabc' or ',بtest'.","commonSituations":"Auto-generated slugs that prefix Arabic/Hebrew words with ASCII digits or punctuation; user handles or subdomains beginning with a number followed by RTL text; data migration that prepended a marker character to existing IDN names.","solutions":["Restructure the label so a strong L/R/AL letter is first (move digits/punctuation after the first letter).","Strip leading punctuation/digits from user input before IDNA encoding.","Split into multiple labels so each starts with a valid directional character."],"exampleFix":"# before\nidna.encode('1-العرب')  # First codepoint must be L, R or AL\n\n# after\nidna.encode('العرب-1')","handlingStrategy":"validation","validationCode":"import unicodedata\n_VALID_FIRST_BIDI = {'L', 'R', 'AL'}\ndef has_valid_first_bidi(label: str) -> bool:\n    return bool(label) and unicodedata.bidirectional(label[0]) in _VALID_FIRST_BIDI","typeGuard":"import unicodedata\ndef is_strong_directional_start(label: str) -> bool:\n    return bool(label) and unicodedata.bidirectional(label[0]) in {'L', 'R', 'AL'}","tryCatchPattern":"from idna import IDNABidiError\ntry:\n    idna.check_bidi(label)\nexcept IDNABidiError as e:\n    if 'First codepoint' in str(e):\n        label = label.lstrip('0123456789-,.;')  # trim weak leading chars\n    else:\n        raise","preventionTips":["Slugify routines should ensure a leading letter rather than a digit/punct.","Validate the first character's bidi class before encoding.","Avoid prefixing RTL labels with ASCII digits or punctuation."],"tags":["idna","bidi","rfc5893","unicode","pip"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}