[elbe-devel] [PATCH 5/6] elbepack: finetuning: be more careful with whitespace in plain encoding
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Mon Jan 27 09:59:19 CET 2025
Discarding all whitespace is problematic if the file needs to contain
some surrounding whitespaces.
Only discard one single newline at the beginning and end.
This keeps the common cases nice and the uncommon ones possible.
Closes: https://github.com/Linutronix/elbe/issues/426
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/finetuning.py | 3 ++-
elbepack/tests/test_finetuning.py | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/elbepack/finetuning.py b/elbepack/finetuning.py
index 63b1b61013e2089d71eb1bfd6fe39fb54e50f4ce..578dde3ead284e1170509a17c8a689a4790ede4b 100644
--- a/elbepack/finetuning.py
+++ b/elbepack/finetuning.py
@@ -8,6 +8,7 @@ import logging
import os
import shlex
import subprocess
+import textwrap
from shutil import rmtree
from gpg import core
@@ -241,7 +242,7 @@ class AddFileAction(FinetuningAction):
@staticmethod
def decode(text, encoding):
if encoding == 'plain':
- msg = strip_leading_whitespace_from_lines(text)
+ msg = textwrap.dedent(text.removeprefix('\n').removesuffix('\n'))
elif encoding == 'raw':
msg = '\n'.join(text.splitlines()[1:-1])
elif encoding == 'base64':
diff --git a/elbepack/tests/test_finetuning.py b/elbepack/tests/test_finetuning.py
index 33c841751250994d93cd57407c4817bc48c7b66a..9d5cec4cbfd91dbef2eefd2cef5786d3192a0993 100644
--- a/elbepack/tests/test_finetuning.py
+++ b/elbepack/tests/test_finetuning.py
@@ -108,7 +108,7 @@ def test_file_plain(target):
</file>
""")
- assert target.read_file('foo') == 'baz'
+ assert target.read_file('foo') == '\nbaz\n'
def test_file_raw(target):
--
2.48.1
More information about the elbe-devel
mailing list