diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2021-05-26 11:55:24 -0400 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2021-06-08 12:45:00 -0400 |
commit | a3c1caad21160545eda87ea1fde93e972a6fbf88 (patch) | |
tree | 7ecd319e916aa027a90553be717f3b15dbabb924 | |
parent | 9c5fc356cfcd1092910941a4027ebe5fcda2b1f4 (diff) | |
download | sos-a3c1caad21160545eda87ea1fde93e972a6fbf88.tar.gz |
[cleaner] Don't strip empty lines from substituted files
Fixes an issue where empty lines would be stripped from files that have
other obfuscations in them. Those empty lines may be important for file
structure and/or readability, so we should instead simply not pass empty
lines to the parsers rather than skipping them wholesale in the flow of
writing obfuscations to a temp file before replacing the source file
with a potentially changed temp file.
Resolves: #2562
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/cleaner/__init__.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/sos/cleaner/__init__.py b/sos/cleaner/__init__.py index bdd24f95..55465b85 100644 --- a/sos/cleaner/__init__.py +++ b/sos/cleaner/__init__.py @@ -603,8 +603,6 @@ third party. tfile = tempfile.NamedTemporaryFile(mode='w', dir=self.tmpdir) with open(filename, 'r') as fname: for line in fname: - if not line.strip(): - continue try: line, count = self.obfuscate_line(line) subs += count @@ -642,7 +640,11 @@ third party. Returns the fully obfuscated line and the number of substitutions made """ + # don't iterate over blank lines, but still write them to the tempfile + # to maintain the same structure when we write a scrubbed file back count = 0 + if not line.strip(): + return line, count for parser in self.parsers: try: line, _count = parser.parse_line(line) |