Tighten regex rule to discard IP address as hostname
authorIndrajit Raychaudhuri <redacted>
Tue, 20 Jun 2017 01:23:00 +0000 (20:23 -0500)
committerIndrajit Raychaudhuri <redacted>
Tue, 20 Jun 2017 07:06:31 +0000 (02:06 -0500)
updateHostsFile.py

index 4de7f3eb08d4b4ea0569f11aa6e7e46df1f9bd5a..59c9b6d617d64c55e557cbd30fc510f8f4661c29 100644 (file)
@@ -501,7 +501,8 @@ def normalize_rule(rule):
         The rule string with spelling and spacing reformatted.
     """
 
-    result = re.search(r'^[ \t]*(\d+\.\d+\.\d+\.\d+)\s+([\w\.-]+)(.*)', rule)
+    result = re.search(r'^\s*(\d{1,3}\.){3}\d{1,3}\s+([\w\.-]+[a-zA-Z])(.*)',
+                       rule)
     if result:
         hostname, suffix = result.group(2, 3)
 
git clone https://git.99rst.org/PROJECT