Fix issue when we meet something like `0.0.0.0 `
authorfunilrys <redacted>
Wed, 30 Jan 2019 00:08:59 +0000 (01:08 +0100)
committerfunilrys <redacted>
Wed, 30 Jan 2019 00:08:59 +0000 (01:08 +0100)
This patch fix StevenBlack/hosts#904

updateHostsFile.py

index 541b6034a06e6b09ab2113ec2ea3f6c5aa2edb87..06fadb192cb355d77ed40be8131266f41cd0332d 100644 (file)
@@ -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")
git clone https://git.99rst.org/PROJECT