prevent universal_newlines modifying --draft output #525
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixes #524
News fragments are read in binary mode, so on Windows they keep their
\r\n
newlines. When these are echoed to the console in--draft
mode, Python's universal newlines support converts the\n
toos.linesep
(\r\n
), leaving them as\r\r\n
. If this output is then read by Python again (in text mode), that same newline support converts both\r
and\r\n
into\n
, causing all newlines to be doubled up (\n\n
). This commit echoes the--draft
output as utf8 encodedbytes
rather than astr
to prevent this from happening. This also matches the behaviour of writing to a newsfile in non-draft mode.@adiroiban please let me know what tests (if any) you think would be appropriate for this change and I will add them. I will also add a news fragment detailing the change if you are minded to accept the change.
Checklist
src/towncrier/newsfragments/
. Describe yourchange and include important information. Your change will be included in the public release notes.
docs/tutorial.rst
is still up-to-date.docs/cli.rst
reflects those changes.docs/configuration.rst
reflects those changes.