Skip to content
Myr

Merge pull request #1468 from muggenhor/fix/utf-8-compat

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

authored by David Lord · committed by GitHub · parents 9ba75de, f6710e5 · Browse files · 2 files+24 added−1 removed
This commit

State

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

Trailers

  • fix: always use parameter UTF-8 fallback

Diff stats

2 files+24 added−1 removed

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

2 files+24 added−1 removed

modified:click/types.py+2 added
117 unmodified lines
118 try:119 value = value.decode(fs_enc)120 except UnicodeError:121 value = value.decode('utf-8', 'replace')122 else:123 value = value.decode('utf-8', 'replace')124 return value125 return value126127 def __repr__(self):
552 unmodified lines
modified:tests/test_arguments.py+22 added-1 removed
1# -*- coding: utf-8 -*-2import pytest3import click4import sys4from click._compat import PY25from click._compat import PY2, text_type678def test_nargs_star(runner):9 @click.command()
74 unmodified lines
84 assert result.exit_code == 285 assert 'Got unexpected extra argument (bar)' in result.output868788def test_bytes_args(runner, monkeypatch):89 @click.command()90 @click.argument('arg')91 def from_bytes(arg):92 assert isinstance(arg, text_type), "UTF-8 encoded argument should be implicitly converted to Unicode"9394 # Simulate empty locale environment variables95 if PY2:96 monkeypatch.setattr(sys.stdin, 'encoding', 'ANSI_X3.4-1968')97 monkeypatch.setattr(sys, 'getfilesystemencoding', lambda: 'ANSI_X3.4-1968')98 monkeypatch.setattr(sys, 'getdefaultencoding', lambda: 'ascii')99 else:100 monkeypatch.setattr(sys.stdin, 'encoding', 'utf-8')101 monkeypatch.setattr(sys, 'getfilesystemencoding', lambda: 'utf-8')102 monkeypatch.setattr(sys, 'getdefaultencoding', lambda: 'utf-8')103104 runner.invoke(from_bytes, [u'Something outside of ASCII range: 林'.encode('UTF-8')],105 catch_exceptions=False)106107108def test_file_args(runner):109 @click.command()110 @click.argument('input', type=click.File('rb'))111 @click.argument('output', type=click.File('wb'))
217 unmodified lines