From 71745f006de63edfb8d6f88958ea201ff0303a68 Mon Sep 17 00:00:00 2001 From: Dennis Brakhane Date: Tue, 16 Oct 2018 16:49:18 +0200 Subject: [PATCH] fix crash on missing comments Some DMARC reports contain the "comment" field with a null value. This would case a crash when trying to combine the comments into one. Therefore, handle None comments as well. Also remove a buggy line; the reason object already exists in the list, so no need to append it (and even if we needed to append it, we would need to iterate over a copy, otherwise we might end up in an endless loop) --- parsedmarc/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/parsedmarc/__init__.py b/parsedmarc/__init__.py index e6e68ba..43ab416 100644 --- a/parsedmarc/__init__.py +++ b/parsedmarc/__init__.py @@ -125,8 +125,7 @@ def _parse_report_record(record, nameservers=None, timeout=2.0): reasons = [policy_evaluated["reason"]] for reason in reasons: if "comment" not in reason: - reason["comment"] = "none" - reasons.append(reason) + reason["comment"] = None new_policy_evaluated["policy_override_reasons"] = reasons new_record["policy_evaluated"] = new_policy_evaluated new_record["identifiers"] = record["identifiers"].copy() @@ -454,7 +453,7 @@ def parsed_aggregate_reports_to_csv(reports): policy_override_reasons = list(map(lambda r: r["type"], record["policy_evaluated"] ["policy_override_reasons"])) - policy_override_comments = list(map(lambda r: r["comment"], + policy_override_comments = list(map(lambda r: r["comment"] or "none", record["policy_evaluated"] ["policy_override_reasons"])) row["policy_override_reasons"] = ",".join(