diff --git a/zerver/webhooks/slack_incoming/fixtures/attachment_fields.json b/zerver/webhooks/slack_incoming/fixtures/attachment_fields.json index 72232d6466..99387d0db4 100644 --- a/zerver/webhooks/slack_incoming/fixtures/attachment_fields.json +++ b/zerver/webhooks/slack_incoming/fixtures/attachment_fields.json @@ -19,12 +19,20 @@ "short": true }, { - "title": "Title without value", + "title": "Title with null value", "value": null, "short": true }, + { + "title": "Title without value", + "short": true + }, { "title": null, + "value": "Value with null title", + "short": true + }, + { "value": "Value without title", "short": true }, diff --git a/zerver/webhooks/slack_incoming/tests.py b/zerver/webhooks/slack_incoming/tests.py index 9fc590d819..ae823b01ee 100644 --- a/zerver/webhooks/slack_incoming/tests.py +++ b/zerver/webhooks/slack_incoming/tests.py @@ -191,7 +191,9 @@ Build bla bla succeeded **Requested by**: Some user **Duration**: 00:02:03 **Build pipeline**: ConsumerAddressModule +**Title with null value** **Title without value** +Value with null title Value without title """.strip() diff --git a/zerver/webhooks/slack_incoming/view.py b/zerver/webhooks/slack_incoming/view.py index dc90d8ef7c..c22baccac2 100644 --- a/zerver/webhooks/slack_incoming/view.py +++ b/zerver/webhooks/slack_incoming/view.py @@ -193,14 +193,14 @@ def render_attachment(attachment: WildValue) -> str: if "fields" in attachment: fields = [] for field in attachment["fields"]: - if field["title"] and field["value"]: + if "title" in field and "value" in field and field["title"] and field["value"]: title = field["title"].tame(check_string) value = field["value"].tame(check_string) fields.append(f"*{title}*: {value}") - elif field["title"]: + elif "title" in field and field["title"]: title = field["title"].tame(check_string) fields.append(f"*{title}*") - elif field["value"]: + elif "value" in field and field["value"]: value = field["value"].tame(check_string) fields.append(f"{value}") pieces.append("\n".join(fields))