From 11c8f516787c3fc3b879a8efa228c65a4fc2dd70 Mon Sep 17 00:00:00 2001 From: Thomas Krennwallner Date: Fri, 24 May 2024 22:32:51 +0200 Subject: [PATCH 1/2] senders: check tags for None keys/values Only include tags that have no None-valued keys/values. --- journalpump/senders/base.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/journalpump/senders/base.py b/journalpump/senders/base.py index 267e3e8..5a3b00c 100644 --- a/journalpump/senders/base.py +++ b/journalpump/senders/base.py @@ -45,9 +45,10 @@ def make_tags(self, tags: Optional[Dict[str, str]] = None) -> Dict[str, str]: output = self._tags.copy() if tags: for tag_name, tag_value in tags.items(): - sanitized_name = self.unsafe_tag_name_chars.sub("_", tag_name).strip("_") - sanitized_value = self.unsafe_tag_value_chars.sub("_", tag_value).strip("_") - output[sanitized_name] = sanitized_value + if tag_name is not None and tag_value is not None: + sanitized_name = self.unsafe_tag_name_chars.sub("_", tag_name).strip("_") + sanitized_value = self.unsafe_tag_value_chars.sub("_", tag_value).strip("_") + output[sanitized_name] = sanitized_value return output def replace_tags(self, tags): From 822f12b54ff017ea8b2d7ae0ddb63369bd7981ff Mon Sep 17 00:00:00 2001 From: Thomas Krennwallner Date: Sun, 26 May 2024 23:26:58 +0200 Subject: [PATCH 2/2] test: verify tags with None keys/values --- test/unit/senders/test_base.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/senders/test_base.py b/test/unit/senders/test_base.py index 2fc899c..cc50c80 100644 --- a/test/unit/senders/test_base.py +++ b/test/unit/senders/test_base.py @@ -7,6 +7,7 @@ "input_tags,expected_output_tags", [ ({"foo": "bar"}, {"foo": "bar"}), + ({"foo": "bar", "bar": None, None: "baz"}, {"foo": "bar"}), ({"foo|wow,": "super!cool"}, {"foo_wow": "super!cool"}), ({"host": "localhost:1234"}, {"host": "localhost_1234"}), ({"base64": "YmFzZTY0Cg=="}, {"base64": "YmFzZTY0Cg"}),