Skip to content
Myr

Fix crash when writing to unicode files

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix #339

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parent be2c42b · Browse files · 3 files+9 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+9 added−1 removed

  • tests:+7 added−0 removed
  • other:+2 added−1 removed

3 files+9 added−1 removed

modified:click/utils.py+1 added-1 removed
290 unmodified lines
291292 if message:293 file.write(message)294 if nl:295 file.write('\n')295 file.write(u'\n')296 file.flush()297298299def get_binary_stream(name):
131 unmodified lines
modified:tests/test_utils.py+7 added
37 unmodified lines
38 click.echo(bytearray(b'\x1b[31mx\x1b[39m'), nl=False)39 assert out.getvalue() == b'\x1b[31mx\x1b[39m'404142def test_echo_custom_file():43 import io44 f = io.StringIO()45 click.echo(u'hello', file=f)46 assert f.getvalue() == u'hello\n'474849def test_styling():50 examples = [51 ('x', dict(fg='black'), '\x1b[30mx\x1b[0m'),52 ('x', dict(fg='red'), '\x1b[31mx\x1b[0m'),
184 unmodified lines
modified:CHANGES+1 added
12 unmodified lines
13- Support streams with encoding set to `None` on Python 3 by barfing with14 a better error.15- Handle ^C in less-pager properly.16- Handle return value of `None` from `sys.getfilesystemencoding`17- Fix crash when writing to unicode files with `click.echo`.1819Version 4.020-----------21
207 unmodified lines