Skip to content

Commit

Permalink
Don't throw when using normalize_name w/ ENSIP-15 if name is empty
Browse files Browse the repository at this point in the history
- This causes methods that utilize normalize_name() internally to throw with a very obscure message that empty names aren't allowed. e.g. when calling ns.name(ens_address), if the reverse resolver isn't properly set up it will throw ``InvalidName`` with a message saying names can't be empty. This would create a lot of confusion.
- ``normalize_name_ensip15()`` method still raises ``InvalidName`` on empty name and this seems more appropriate when directly calling the method.
  • Loading branch information
fselmo committed Jul 7, 2023
1 parent 7af4664 commit a1045aa
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ens/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def normalize_name(name: str, ensip15: bool = False) -> str:
:param bool ensip15: if True, normalize as per ENSIP-15
:raises InvalidName: if ``name`` has invalid syntax
"""
if is_empty_name(name):
return ""

if ensip15:
return normalize_name_ensip15(name).as_text

Expand All @@ -137,9 +140,7 @@ def normalize_name(name: str, ensip15: bool = False) -> str:
FutureWarning,
)

if not name:
return name
elif isinstance(name, (bytes, bytearray)):
if isinstance(name, (bytes, bytearray)):
name = name.decode("utf-8")

try:
Expand Down

0 comments on commit a1045aa

Please sign in to comment.