From 94ea41fa161e50920693d3ce8c52d6fb2dfda5e6 Mon Sep 17 00:00:00 2001 From: Steven Black Date: Thu, 24 Mar 2016 18:32:46 -0400 Subject: [PATCH] =?UTF-8?q?Issue=20#77:=20fix=20=E2=80=94=20account=20for?= =?UTF-8?q?=20empty=20lines.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- updateHostsFile.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/updateHostsFile.py b/updateHostsFile.py index 94bce08bb..a6133cf61 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -315,12 +315,14 @@ def removeDupsAndExcl(mergeFile): exclusions = settings["exclusions"] for line in mergeFile.readlines(): write = 'true' - # Trim trailing whitespace - line = line.rstrip() # Explicit encoding line = line.decode("UTF-8") # replace tabs with space line = line.replace('\t+', ' ') + # Trim trailing whitespace + line = line.rstrip() + if not line: + continue # Testing the first character doesn't require startswith if line[0] == '#' or re.match(r'^\s*$', line[0]): # Cross-python write