1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix sanitizing config lines (#50553)

Previously, the index got out of sync with the actual config list. Invoked with lines:
  - bad
  - first
  - bad
  - second
the sanitization would first delete index 0 and then index 2, which would result in the output
  - first
  - bad
By reversing the list, we avoid that problem (though a filter() would be nicer)
This commit is contained in:
Jan-Philipp Litza 2019-01-09 16:56:30 +01:00 committed by Nathaniel Case
parent cb89b1758d
commit 636e1d5fcb

View file

@ -207,7 +207,7 @@ def diff_config(commands, config):
def sanitize_config(config, result):
result['filtered'] = list()
for regex in CONFIG_FILTERS:
for index, line in enumerate(list(config)):
for index, line in reversed(list(enumerate(config))):
if regex.search(line):
result['filtered'].append(line)
del config[index]