Skip to content

Commit 580ece9

Browse files
committed
1 parent 5343dd5 commit 580ece9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

idna/core.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
_virama_combining_class = 9
1010
_alabel_prefix = b"xn--"
1111
_unicode_dots_re = re.compile("[\u002e\u3002\uff0e\uff61]")
12-
12+
_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,
13+
111,112,113,114,115,116,117,118,119,120,121,122)
1314

1415
class IDNAError(UnicodeError):
1516
"""Base exception for all IDNA-encoding related problems"""
@@ -341,16 +342,18 @@ def uts46_remap(domain: str, std3_rules: bool = True, transitional: bool = False
341342
uts46row = uts46data[code_point if code_point < 256 else bisect.bisect_left(uts46data, (code_point, "Z")) - 1]
342343
status = uts46row[1]
343344
replacement: Optional[str] = None
345+
if std3_rules and code_point <= 0x7f:
346+
if not code_point in _ldh:
347+
raise InvalidCodepoint("Codepoint {} at position {} does not follow STD3 rules".format(_unot(code_point), pos + 1))
344348
if len(uts46row) == 3:
345349
replacement = uts46row[2]
346350
if (
347351
status == "V"
348352
or (status == "D" and not transitional)
349-
or (status == "3" and not std3_rules and replacement is None)
350353
):
351354
output += char
352355
elif replacement is not None and (
353-
status == "M" or (status == "3" and not std3_rules) or (status == "D" and transitional)
356+
status == "M" or (status == "D" and transitional)
354357
):
355358
output += replacement
356359
elif status != "I":

0 commit comments

Comments
 (0)