Fix bug in preprocessing when wrapped line is appended to a non-existing entry. (#177)

This commit is contained in:
Felix Fontein 2023-06-09 06:03:42 +02:00 committed by GitHub
parent 2b8c66b983
commit 42ea132d60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 2 deletions

View file

@ -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)."

View file

@ -391,7 +391,7 @@ class Interfaces(FactsBase):
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 @@ class Routing(FactsBase):
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