Skip to content

Commit

Permalink
Fix encoding errors due to compatibility between #151 and #154
Browse files Browse the repository at this point in the history
  • Loading branch information
nozmore-vera committed Apr 13, 2021
1 parent da9df14 commit 002e0ea
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pytm/pytm.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,12 @@ def __init__(self, **kwargs):
self.example = kwargs.get("example", "")
self.references = kwargs.get("references", "")

def _safeset(self, attr, value):
try:
setattr(self, attr, value)
except ValueError:
pass

def __repr__(self):
return "<{0}.{1}({2}) at {3}>".format(
self.__module__, type(self).__name__, self.id, hex(id(self))
Expand Down Expand Up @@ -598,6 +604,12 @@ def __init__(
for k, v in kwargs.items():
setattr(self, k, v)

def _safeset(self, attr, value):
try:
setattr(self, attr, value)
except ValueError:
pass

def __repr__(self):
return "<{0}.{1}({2}) at {3}>".format(
self.__module__, type(self).__name__, self.id, hex(id(self))
Expand Down Expand Up @@ -1701,9 +1713,16 @@ def encode_threat_data(obj):
for e in obj:
t = copy.deepcopy(e)

if (isinstance(t, Finding)):
attrs.append("threat_id")

for a in attrs:
v = getattr(e, a)
setattr(t, a, html.escape(v))

if (isinstance(v, int)):
t._safeset(a, v)
else:
t._safeset(a, html.escape(v))

encoded_threat_data.append(t)

Expand Down

0 comments on commit 002e0ea

Please sign in to comment.