diff --git a/fix_encoding.py b/fix_encoding.py index 1d84750e7..b14494f39 100644 --- a/fix_encoding.py +++ b/fix_encoding.py @@ -276,6 +276,11 @@ class WinUnicodeOutput(WinUnicodeOutputBase): if sys.version_info.major == 3 and isinstance(text, bytes): # Replace characters that cannot be printed instead of failing. text = text.decode(self.encoding, 'replace') + # When redirecting to a file or process any \n characters will be replaced + # with \r\n. If the text to be printed already has \r\n line endings then + # \r\r\n line endings will be generated, leading to double-spacing of some + # output. Normalizing line endings to \n avoids this problem. + text = text.replace('\r\n', '\n') self._stream.write(text) except Exception as e: complain('%s.write: %r' % (self.name, e))