{"record":{"id":"7b7d7da809ff268b","repo":"pypa/pip","slug":"empty-domain","errorCode":null,"errorMessage":"Empty domain","messagePattern":"Empty domain","errorType":"exception","errorClass":"IDNAError","httpStatus":null,"severity":"error","filePath":"src/pip/_vendor/idna/core.py","lineNumber":630,"sourceCode":"    \"\"\"\n    if not isinstance(s, str):\n        try:\n            s = str(s, \"ascii\")\n        except (UnicodeDecodeError, TypeError) as err:\n            raise IDNAError(\"Invalid ASCII in A-label\") from err\n    if len(s) > _max_input_length:\n        raise IDNAError(\"Domain too long\")\n    if uts46:\n        s = uts46_remap(s, std3_rules, False)\n    # Reject inputs that exceed the maximum DNS domain length up-front\n    # to avoid expensive computation on long inputs.\n    if not valid_string_length(s, trailing_dot=True):\n        raise IDNAError(\"Domain too long\")\n    trailing_dot = False\n    result = []\n    labels = s.split(\".\") if strict else _unicode_dots_re.split(s)\n    if not labels or labels == [\"\"]:\n        raise IDNAError(\"Empty domain\")\n    if not labels[-1]:\n        del labels[-1]\n        trailing_dot = True\n    for label in labels:\n        try:\n            u = ulabel(label)\n        except IDNAError:\n            if display and label[:4].lower() == \"xn--\":\n                u = label.lower()\n            else:\n                raise\n        if u:\n            result.append(u)\n        else:\n            raise IDNAError(\"Empty label\")\n    if trailing_dot:\n        result.append(\"\")\n    return \".\".join(result)","sourceCodeStart":612,"sourceCodeEnd":648,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_vendor/idna/core.py#L612-L648","documentation":"Raised by idna.encode and idna.decode when the input domain string is effectively empty — after splitting on label separators, labels is empty or equals ['']. This catches inputs like '', or strings consisting only of separator characters.","triggerScenarios":"Calling idna.encode('') or idna.decode(''), or passing a string of only dots such as '.' or '...' where all labels are stripped.","commonSituations":"Empty hostname field from a parsed URL; user form with blank domain; programmatic generation that produces empty strings; default/placeholder values passed through.","solutions":["Check for empty or whitespace-only input before calling encode/decode.","Treat empty hostname as a special case (e.g. use 'localhost' or reject the form).","Validate the URL contains a non-empty hostname before extracting it for IDNA."],"exampleFix":"# before\nhost = parsed.hostname or ''\nidna.encode(host)  # raises Empty domain when host is ''\n\n# after\nhost = parsed.hostname\nif not host:\n    raise ValueError('Hostname is required')\nidna.encode(host)","handlingStrategy":"validation","validationCode":"def is_non_empty_domain(domain: str) -> bool:\n    return bool(domain and domain.strip())","typeGuard":"def is_non_empty_domain(domain: str) -> bool:\n    return isinstance(domain, str) and len(domain.strip()) > 0","tryCatchPattern":"from idna.core import IDNAError\ntry:\n    result = idna.encode(domain)\nexcept IDNAError:\n    if not domain:\n        raise ValueError('Domain must not be empty')\n    raise","preventionTips":["Check for empty/None hostnames before IDNA encoding.","Use URL parsing to validate hostname presence.","Provide sensible defaults for missing hostnames."],"tags":["idna","dns","validation","empty-input"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}