{"id":"39ac96b5ef0d8943","repo":"pypa/pip","slug":"label-has-disallowed-hyphens-in-3rd-and-4th-positi","errorCode":null,"errorMessage":"Label has disallowed hyphens in 3rd and 4th position","messagePattern":"Label has disallowed hyphens in 3rd and 4th position","errorType":"validation","errorClass":"IDNAError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/idna/core.py","lineNumber":201,"sourceCode":"    \"\"\"\n    if unicodedata.category(label[0])[0] == \"M\":\n        raise IDNAError(\"Label begins with an illegal combining character\")\n    return True\n\n\ndef check_hyphen_ok(label: str) -> bool:\n    \"\"\"Validate the hyphen restrictions for a label.\n\n    Per :rfc:`5891` §4.2.3.1 a label must not start or end with a hyphen\n    (``U+002D``), and must not have hyphens in both the third and fourth\n    positions (the prefix reserved for A-labels).\n\n    :param label: The label to check.\n    :returns: ``True`` if the hyphen restrictions are satisfied.\n    :raises IDNAError: If any of the hyphen restrictions are violated.\n    \"\"\"\n    if label[2:4] == \"--\":\n        raise IDNAError(\"Label has disallowed hyphens in 3rd and 4th position\")\n    if label[0] == \"-\" or label[-1] == \"-\":\n        raise IDNAError(\"Label must not start or end with a hyphen\")\n    return True\n\n\ndef check_nfc(label: str) -> None:\n    \"\"\"Require that a label is in Unicode Normalization Form C.\n\n    :param label: The label to check.\n    :raises IDNAError: If ``label`` differs from its NFC normalisation.\n    \"\"\"\n    if len(label) > _max_input_length:\n        raise IDNAError(\"Label too long\")\n    if unicodedata.normalize(\"NFC\", label) != label:\n        raise IDNAError(\"Label must be in Normalization Form C\")\n\n\ndef valid_contextj(label: str, pos: int) -> bool:","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/pypa/pip/blob/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_vendor/idna/core.py#L183-L219","documentation":"IDNAError from check_hyphen_ok: per RFC 5891 §4.2.3.1 a label must not contain hyphens in both the 3rd and 4th positions (label[2:4] == '--'). That pattern is reserved as the prefix of ACE (Punycode) A-labels ('xn--'), and a U-label matching it would be ambiguous.","triggerScenarios":"A non-ASCII U-label whose 3rd and 4th characters are both hyphens, e.g. 'ab--العرب'. Encountered when alabel/check_label processes a label that was not already an xn-- A-label but happens to match the reserved prefix shape.","commonSituations":"Auto-generated names of the form '<2chars>--<rest>'; user handles containing a double-hyphen after a short prefix; data from a system that uses '--' as a separator glued directly to a 2-char prefix.","solutions":["Avoid placing '--' at positions 3-4; use a different separator or pad the prefix to 3+ characters before the hyphens.","If the input is already an A-label (xn--...), pass it through ulabel/decode rather than re-encoding via alabel.","Rename the label so the double hyphen appears elsewhere."],"exampleFix":"# before\nidna.encode('ab--العرب')  # disallowed hyphens in 3rd and 4th position\n\n# after\nidna.encode('abc--العرب')  # double hyphen no longer at 3-4","handlingStrategy":"validation","validationCode":"def avoids_reserved_ace_prefix(label: str) -> bool:\n    return label[2:4] != '--'","typeGuard":"def is_safe_label_for_ace(label: str) -> bool:\n    return len(label) < 4 or label[2:4] != '--'","tryCatchPattern":"from idna import IDNAError\ntry:\n    idna.encode(label)\nexcept IDNAError as e:\n    if '3rd and 4th' in str(e):\n        # relocate the double-hyphen away from positions 3-4\n        raise ValueError('reserved ACE prefix shape; rename label') from e\n    raise","preventionTips":["Do not place '--' at positions 3-4 of a U-label; that shape is reserved for xn-- A-labels.","If the input is already an xn-- A-label, decode it via idna.decode rather than re-encoding.","Use a separator other than '--' in generated names."],"tags":["idna","rfc5891","dns","hyphens","punycode","pip"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}