1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 20:51:30 +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

@@ -84,7 +84,7 @@ class ScriptDB (object):
self.lineno = 1
self.line = ""
with open(script_db_path, "r") as self.f:
with open(script_db_path, "r", encoding="utf-8") as self.f:
self.entries_list = self.parse()
def syntax_error(self, message):
@@ -296,20 +296,20 @@ class ScriptMetadata (object):
self.get_string_variable(filename, "author")]
filepath = os.path.join(self.scripts_dir, filename)
with open(filepath, "r") as f:
with open(filepath, "r", encoding="utf-8") as f:
for tag_name, tag_text in nsedoc_tags_iter(f):
if tag_name == "output" and not entry.output:
entry.output = tag_text
elif tag_name == "usage" and not entry.usage:
entry.usage = tag_text
except IOError as e:
except (IOError, UnicodeError) as e:
entry.description = "Error getting metadata: {}".format(e)
return entry
@staticmethod
def get_file_contents(filename):
with open(filename, "r") as f:
with open(filename, "r", encoding="utf-8") as f:
contents = f.read()
return contents
@@ -343,7 +343,7 @@ class ScriptMetadata (object):
@staticmethod
def get_requires(filename):
with open(filename, "r") as f:
with open(filename, "r", encoding="utf-8") as f:
requires = ScriptMetadata.get_requires_from_file(f)
return requires
@@ -359,7 +359,7 @@ class ScriptMetadata (object):
@staticmethod
def get_script_args(filename):
with open(filename, "r") as f:
with open(filename, "r", encoding="utf-8") as f:
args = ScriptMetadata.get_script_args_from_file(f)
return args
@@ -414,8 +414,11 @@ class ScriptMetadata (object):
else:
libname = filename
self.library_arguments[libname] = self.get_script_args(filepath)
self.library_requires[libname] = self.get_requires(filepath)
try:
self.library_arguments[libname] = self.get_script_args(filepath)
self.library_requires[libname] = self.get_requires(filepath)
except (IOError, UnicodeError) as e:
log.debug("Unable to process {}: {}".format(libname, e))
def get_script_entries(scripts_dir, nselib_dir):
@@ -424,7 +427,8 @@ def get_script_entries(scripts_dir, nselib_dir):
metadata = ScriptMetadata(scripts_dir, nselib_dir)
try:
scriptdb = ScriptDB(os.path.join(scripts_dir, "script.db"))
except IOError:
except (IOError, UnicodeError) as e:
log.debug("Unable to process script.db: {}".format(e))
return []
entries = []
for dbentry in scriptdb.get_entries_list():