From 7113e5a844fc0304f62f4afe65b5cbc816f75372 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Thu, 14 Nov 2019 21:55:08 -0800 Subject: [PATCH] filter out comments at the end of the line --- jc/parsers/hosts.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/jc/parsers/hosts.py b/jc/parsers/hosts.py index faa40613..d1090009 100644 --- a/jc/parsers/hosts.py +++ b/jc/parsers/hosts.py @@ -120,6 +120,16 @@ def parse(data, raw=False, quiet=False): hosts = line_list[1] hosts_list = hosts.split() + comment_found = False + for i, item in enumerate(hosts_list): + if item.find('#') != -1: + comment_found = True + comment_item = i + break + + if comment_found: + hosts_list = hosts_list[:comment_item] + output_line['ip'] = ip output_line['hostname'] = hosts_list