1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-07 05:01:29 +00:00

Ensure UTF-8 encoding used throughout zenmap

This commit is contained in:
dmiller
2024-04-26 17:25:40 +00:00
parent 480803e24a
commit c840e236cb
12 changed files with 48 additions and 36 deletions

View File

@@ -739,7 +739,7 @@ class NmapParserSAX(ParserBasics, ContentHandler):
def parse_file(self, filename):
"""Parse an Nmap XML file from the named file."""
with open(filename, "r") as f:
with open(filename, "rb") as f:
self.parse(f)
self.filename = filename
@@ -1002,12 +1002,12 @@ class NmapParserSAX(ParserBasics, ContentHandler):
f."""
if self.nmap_output == "":
return
f.write(self.nmap_output)
f.write(self.nmap_output.encode('utf-8','xmlcharrefreplace'))
def write_xml(self, f):
"""Write the XML representation of this object to the file-like object
f."""
writer = XMLGenerator(f)
writer = XMLGenerator(f, encoding='utf-8')
writer.startDocument()
if self.xml_stylesheet_data is not None:
writer.processingInstruction(
@@ -1033,7 +1033,7 @@ class NmapParserSAX(ParserBasics, ContentHandler):
def write_xml_to_file(self, filename):
"""Write the XML representation of this scan to the file whose name is
given."""
fd = open(filename, "w")
fd = open(filename, "wb")
self.write_xml(fd)
fd.close()