Skip to content

Commit 506beb7

Browse files
committed
Fixed indentation logic to also honor blank lines.
1 parent dad7380 commit 506beb7

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

importlib_metadata/_adapters.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
class RawPolicy(email.policy.EmailPolicy):
1010
def fold(self, name, value):
1111
folded = self.linesep.join(
12-
textwrap.indent(value, prefix=' ' * 8).lstrip().splitlines()
12+
textwrap.indent(value, prefix=' ' * 8, predicate=lambda line: True)
13+
.lstrip()
14+
.splitlines()
1315
)
1416
return f'{name}: {folded}{self.linesep}'
1517

@@ -29,10 +31,12 @@ class Message(email.message.Message):
2931
... <BLANKLINE>
3032
... First line of description.
3133
... Second line of description.
34+
... <BLANKLINE>
35+
... Fourth line!
3236
... ''').lstrip().replace('<BLANKLINE>', '')
3337
>>> msg = Message(email.message_from_string(msg_text))
3438
>>> msg['Description']
35-
'First line of description.\nSecond line of description.\n'
39+
'First line of description.\nSecond line of description.\n\nFourth line!\n'
3640
3741
Message should render even if values contain newlines.
3842
@@ -43,6 +47,8 @@ class Message(email.message.Message):
4347
de-blah
4448
Description: First line of description.
4549
Second line of description.
50+
<BLANKLINE>
51+
Fourth line!
4652
<BLANKLINE>
4753
<BLANKLINE>
4854
"""

newsfragments/+bd6aec5a.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed indentation logic to also honor blank lines.

0 commit comments

Comments
 (0)