Skip to content

Commit

Permalink
Gracefully fail IDNA for hostnames with underscores (fixes #53)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchop committed Apr 17, 2017
1 parent 3ff8a75 commit 0ece661
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions core/observables/hostname.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ def normalize(self, hostname):
hostname = Hostname.check_type(hostname)
if not hostname:
raise ObservableValidationError("Invalid Hostname (check_type={}): {}".format(Hostname.check_type(hostname), hostname))

self.idna = unicode(idna.encode(hostname.lower()))
self.value = unicode(idna.decode(hostname.lower()))
self.value = unicode(hostname.lower())
try:
self.idna = unicode(idna.encode(hostname.lower()))
except idna.core.InvalidCodepoint:
pass

@staticmethod
def check_type(txt):
Expand Down

0 comments on commit 0ece661

Please sign in to comment.