Skip to content

Commit

Permalink
Fixed indentation logic to also honor blank lines.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Jan 20, 2025
1 parent dad7380 commit 506beb7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions importlib_metadata/_adapters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
class RawPolicy(email.policy.EmailPolicy):
def fold(self, name, value):
folded = self.linesep.join(
textwrap.indent(value, prefix=' ' * 8).lstrip().splitlines()
textwrap.indent(value, prefix=' ' * 8, predicate=lambda line: True)
.lstrip()
.splitlines()
)
return f'{name}: {folded}{self.linesep}'

Expand All @@ -29,10 +31,12 @@ class Message(email.message.Message):
... <BLANKLINE>
... First line of description.
... Second line of description.
... <BLANKLINE>
... Fourth line!
... ''').lstrip().replace('<BLANKLINE>', '')
>>> msg = Message(email.message_from_string(msg_text))
>>> msg['Description']
'First line of description.\nSecond line of description.\n'
'First line of description.\nSecond line of description.\n\nFourth line!\n'
Message should render even if values contain newlines.
Expand All @@ -43,6 +47,8 @@ class Message(email.message.Message):
de-blah
Description: First line of description.
Second line of description.
<BLANKLINE>
Fourth line!
<BLANKLINE>
<BLANKLINE>
"""
Expand Down
1 change: 1 addition & 0 deletions newsfragments/+bd6aec5a.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed indentation logic to also honor blank lines.

0 comments on commit 506beb7

Please sign in to comment.