Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

slack_incoming: Verify that keys exist before checking their value.

Alex Vandivereb3674362a52
diff --git a/zerver/webhooks/slack_incoming/fixtures/attachment_fields.json b/zerver/webhooks/slack_incoming/fixtures/attachment_fields.json
index 72232d6466b..99387d0db4b 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 9fc590d8199..ae823b01eed 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 dc90d8ef7c4..c22baccac26 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))