Skip to content

🐛 FIX: CLI crash on non-utf8 character #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion markdown_it/cli/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def convert_file(filename: str) -> None:
Parse a Markdown file and dump the output to stdout.
"""
try:
with open(filename, "r") as fin:
with open(filename, "r", encoding="utf8", errors="ignore") as fin:
rendered = MarkdownIt().render(fin.read())
print(rendered, end="")
except OSError:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ def test_parse_fail():
assert exc_info.value.code == 1


def test_non_utf8():
with tempfile.TemporaryDirectory() as tempdir:
path = pathlib.Path(tempdir).joinpath("test.md")
path.write_bytes(b"\x80abc")
assert parse.main([str(path)]) == 0


def test_print_heading():
with patch("builtins.print") as patched:
parse.print_heading()
Expand Down