From: funilrys Date: Wed, 30 Jan 2019 00:08:59 +0000 (+0100) Subject: Fix issue when we meet something like `0.0.0.0 ` X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=90420ae7512aabef2364c51b3c807902288183ba;p=stevenblack-hosts.git Fix issue when we meet something like `0.0.0.0 ` This patch fix StevenBlack/hosts#904 --- diff --git a/updateHostsFile.py b/updateHostsFile.py index 541b6034a..06fadb192 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -1195,26 +1195,29 @@ def domain_to_idna(line): if separator: splited_line = line.split(separator) - index = 1 - while index < len(splited_line): - if splited_line[index]: - break - index += 1 - - if '#' in splited_line[index]: - index_comment = splited_line[index].find('#') - - if index_comment > -1: - comment = splited_line[index][index_comment:] - - splited_line[index] = splited_line[index] \ - .split(comment)[0] \ - .encode("IDNA").decode("UTF-8") + \ - comment - - splited_line[index] = splited_line[index] \ - .encode("IDNA") \ - .decode("UTF-8") + try: + index = 1 + while index < len(splited_line): + if splited_line[index]: + break + index += 1 + + if '#' in splited_line[index]: + index_comment = splited_line[index].find('#') + + if index_comment > -1: + comment = splited_line[index][index_comment:] + + splited_line[index] = splited_line[index] \ + .split(comment)[0] \ + .encode("IDNA").decode("UTF-8") + \ + comment + + splited_line[index] = splited_line[index] \ + .encode("IDNA") \ + .decode("UTF-8") + except IndexError: + pass return separator.join(splited_line) return line.encode("IDNA").decode("UTF-8") return line.encode("UTF-8").decode("UTF-8")