diff options
Diffstat (limited to '')
-rw-r--r-- | debian/patches/0002-fix-dos-casued-by-invalid-utf-8-char-as-input.patch | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/debian/patches/0002-fix-dos-casued-by-invalid-utf-8-char-as-input.patch b/debian/patches/0002-fix-dos-casued-by-invalid-utf-8-char-as-input.patch new file mode 100644 index 0000000..f244847 --- /dev/null +++ b/debian/patches/0002-fix-dos-casued-by-invalid-utf-8-char-as-input.patch @@ -0,0 +1,47 @@ +From e711074fe79be7ff257a41d15969b79edfaa7c8e Mon Sep 17 00:00:00 2001 +From: Chris Sewell <chrisj_sewell@hotmail.com> +Date: Wed, 22 Feb 2023 06:19:13 +0100 +Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20CLI=20crash=20on=20non-ut?= + =?UTF-8?q?f8=20character?= +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit +Bug-Debian: https://bugs.debian.org/1031764 + +--- + markdown_it/cli/parse.py | 2 +- + tests/test_cli.py | 7 +++++++ + 2 files changed, 8 insertions(+), 1 deletion(-) + +diff --git a/markdown_it/cli/parse.py b/markdown_it/cli/parse.py +index 2d74f55a..890d5de3 100644 +--- a/markdown_it/cli/parse.py ++++ b/markdown_it/cli/parse.py +@@ -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: +diff --git a/tests/test_cli.py b/tests/test_cli.py +index 57d6b938..c38e24fd 100644 +--- a/tests/test_cli.py ++++ b/tests/test_cli.py +@@ -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() + |