fix(stdin encoding): added encoding to stdin text

Fixes #243
This commit is contained in:
Christopher Pickering 2022-05-18 08:35:54 -05:00
parent 4906fbc525
commit e906b3e30a
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
2 changed files with 15 additions and 1 deletions

View file

@ -128,7 +128,7 @@ def main(
temp_file = None
if "-" in src:
stdin_stream = click.get_text_stream("stdin")
stdin_stream = click.get_text_stream("stdin", encoding="utf8")
stdin_text = stdin_stream.read()
temp_file = tempfile.NamedTemporaryFile(delete=False)

View file

@ -120,6 +120,20 @@ def test_stdin(runner: CliRunner) -> None:
assert result.output == "<div></div>\n"
def test_stdin_non_ascii(runner: CliRunner) -> None:
result = runner.invoke(djlint, ["-", "--reformat"], input="必須")
assert result.output == "必須\n"
result = runner.invoke(djlint, ["-", "--reformat"], input="Вход")
assert result.output == "Вход\n"
result = runner.invoke(djlint, ["-", "--reformat"], input="çéâêîôûàèìòùëïü")
assert result.output == "çéâêîôûàèìòùëïü\n"
result = runner.invoke(djlint, ["-", "--reformat"], input="😀😂🤣😆🥰")
assert result.output == "😀😂🤣😆🥰\n"
def test_check(runner: CliRunner, tmp_file: TextIO) -> None:
write_to_file(tmp_file.name, b"<div></div>")
result = runner.invoke(djlint, [tmp_file.name, "--check"])