From bba5bacbb5b8475cb39bf4345b2c9ba64d0ae2b4 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Fri, 2 Jun 2023 13:20:07 +0200 Subject: [PATCH] Fix bug in preprocessing when wrapped line is appended to a non-existing entry. --- changelogs/fragments/177-facts-parsing.yml | 2 ++ plugins/modules/facts.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/177-facts-parsing.yml diff --git a/changelogs/fragments/177-facts-parsing.yml b/changelogs/fragments/177-facts-parsing.yml new file mode 100644 index 00000000..d3dd4816 --- /dev/null +++ b/changelogs/fragments/177-facts-parsing.yml @@ -0,0 +1,2 @@ +bugfixes: + - "facts - do not crash in CLI output preprocessing in unexpected situations during line unwrapping (https://github.com/ansible-collections/community.routeros/issues/170, https://github.com/ansible-collections/community.routeros/pull/177)." diff --git a/plugins/modules/facts.py b/plugins/modules/facts.py index 7b1cd0d8..85c0b37c 100644 --- a/plugins/modules/facts.py +++ b/plugins/modules/facts.py @@ -391,7 +391,7 @@ def preprocess(self, data): for line in data.split('\n'): if len(line) == 0 or line[:5] == 'Flags': continue - elif not re.match(self.WRAPPED_LINE_RE, line): + elif not preprocessed or not re.match(self.WRAPPED_LINE_RE, line): preprocessed.append(line) else: preprocessed[-1] += line @@ -468,7 +468,7 @@ def preprocess(self, data): for line in data.split('\n'): if len(line) == 0 or line[:5] == 'Flags': continue - elif not re.match(self.WRAPPED_LINE_RE, line): + elif not preprocessed or not re.match(self.WRAPPED_LINE_RE, line): preprocessed.append(line) else: preprocessed[-1] += line