diff --git a/libnmap/parser.py b/libnmap/parser.py index 21f6a12..ebeab25 100644 --- a/libnmap/parser.py +++ b/libnmap/parser.py @@ -94,7 +94,8 @@ def _parse_xml(cls, nmap_data=None, incomplete=False): "wrong nmap_data type given as argument: cannot parse data" ) - if incomplete is True: + last_line = [i for i in nmap_data.split("\n") if i][-1] + if incomplete is True and not last_line.endswith(""): nmap_data += "" try: diff --git a/libnmap/test/files/1_hosts_incomplete.xml b/libnmap/test/files/1_hosts_incomplete.xml new file mode 100644 index 0000000..3bbe32c --- /dev/null +++ b/libnmap/test/files/1_hosts_incomplete.xml @@ -0,0 +1,28 @@ + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + diff --git a/libnmap/test/test_parser.py b/libnmap/test/test_parser.py index b7f2537..59a1912 100644 --- a/libnmap/test/test_parser.py +++ b/libnmap/test/test_parser.py @@ -13,6 +13,10 @@ def setUp(self): self.flist_full = [ {"file": "%s/%s" % (fdir, "files/2_hosts.xml"), "hosts": 2}, {"file": "%s/%s" % (fdir, "files/1_hosts.xml"), "hosts": 1}, + { + "file": "%s/%s" % (fdir, "files/1_hosts_incomplete.xml"), + "hosts": 1, + }, { "file": "%s/%s" % (fdir, "files/1_hosts_banner_ports_notsyn.xml"), @@ -128,7 +132,7 @@ def test_class_parser(self): fd = open(testfile["file"], "r") s = fd.read() fd.close() - NmapParser.parse(s) + NmapParser.parse(s, incomplete=True) def test_class_ports_parser(self): pdict = NmapParser.parse(self.ports_string)