Skip to content

Commit

Permalink
Implement changes to UTS46 algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
kjd committed Sep 14, 2024
1 parent 5343dd5 commit 580ece9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions idna/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
_virama_combining_class = 9
_alabel_prefix = b"xn--"
_unicode_dots_re = re.compile("[\u002e\u3002\uff0e\uff61]")

_ldh = (48,49,50,51,52,53,54,55,56,57,95,97,98,99,100,101,102,103,104,105,106,107,108,109,110,
111,112,113,114,115,116,117,118,119,120,121,122)

class IDNAError(UnicodeError):
"""Base exception for all IDNA-encoding related problems"""
Expand Down Expand Up @@ -341,16 +342,18 @@ def uts46_remap(domain: str, std3_rules: bool = True, transitional: bool = False
uts46row = uts46data[code_point if code_point < 256 else bisect.bisect_left(uts46data, (code_point, "Z")) - 1]
status = uts46row[1]
replacement: Optional[str] = None
if std3_rules and code_point <= 0x7f:
if not code_point in _ldh:
raise InvalidCodepoint("Codepoint {} at position {} does not follow STD3 rules".format(_unot(code_point), pos + 1))
if len(uts46row) == 3:
replacement = uts46row[2]
if (
status == "V"
or (status == "D" and not transitional)
or (status == "3" and not std3_rules and replacement is None)
):
output += char
elif replacement is not None and (
status == "M" or (status == "3" and not std3_rules) or (status == "D" and transitional)
status == "M" or (status == "D" and transitional)
):
output += replacement
elif status != "I":
Expand Down

0 comments on commit 580ece9

Please sign in to comment.