diff options
| author | jvoisin | 2018-11-07 21:54:34 +0100 |
|---|---|---|
| committer | jvoisin | 2018-11-07 22:07:46 +0100 |
| commit | 8ff57c5803152c619f88e44ffded28540a289d44 (patch) | |
| tree | 1838dbeec208b5007c8f4589c050a128ad016eb4 | |
| parent | 04bb8c8ccfe1fb789ead340e88b18d6ac9b9e908 (diff) | |
Do not display control characters in output
Kudos to Sherry Taylor for reporting this issue ♥
| -rwxr-xr-x | mat2 | 10 | ||||
| -rw-r--r-- | tests/test_climat2.py | 2 |
2 files changed, 11 insertions, 1 deletions
| @@ -6,6 +6,7 @@ import sys | |||
| 6 | import mimetypes | 6 | import mimetypes |
| 7 | import argparse | 7 | import argparse |
| 8 | import logging | 8 | import logging |
| 9 | import unicodedata | ||
| 9 | 10 | ||
| 10 | try: | 11 | try: |
| 11 | from libmat2 import parser_factory, UNSUPPORTED_EXTENSIONS | 12 | from libmat2 import parser_factory, UNSUPPORTED_EXTENSIONS |
| @@ -83,6 +84,15 @@ def __print_meta(filename: str, metadata: dict, depth: int=1): | |||
| 83 | if isinstance(v, dict): | 84 | if isinstance(v, dict): |
| 84 | __print_meta(k, v, depth+1) | 85 | __print_meta(k, v, depth+1) |
| 85 | continue | 86 | continue |
| 87 | |||
| 88 | # Remove control characters | ||
| 89 | # We might use 'Cc' instead of 'C', but better safe than sorry | ||
| 90 | # https://www.unicode.org/reports/tr44/#GC_Values_Table | ||
| 91 | try: | ||
| 92 | v = ''.join(ch for ch in v if not unicodedata.category(ch).startswith('C')) | ||
| 93 | except TypeError: | ||
| 94 | pass # for things that aren't iterable | ||
| 95 | |||
| 86 | try: # FIXME this is ugly. | 96 | try: # FIXME this is ugly. |
| 87 | print(padding + " %s: %s" % (k, v)) | 97 | print(padding + " %s: %s" % (k, v)) |
| 88 | except UnicodeEncodeError: | 98 | except UnicodeEncodeError: |
diff --git a/tests/test_climat2.py b/tests/test_climat2.py index dd7c9b9..53e4f5b 100644 --- a/tests/test_climat2.py +++ b/tests/test_climat2.py | |||
| @@ -121,7 +121,7 @@ class TestGetMeta(unittest.TestCase): | |||
| 121 | proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.pdf'], | 121 | proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.pdf'], |
| 122 | stdout=subprocess.PIPE) | 122 | stdout=subprocess.PIPE) |
| 123 | stdout, _ = proc.communicate() | 123 | stdout, _ = proc.communicate() |
| 124 | self.assertIn(b'producer: pdfTeX-1.40.14', stdout) | 124 | self.assertIn(b'Producer: pdfTeX-1.40.14', stdout) |
| 125 | 125 | ||
| 126 | def test_png(self): | 126 | def test_png(self): |
| 127 | proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.png'], | 127 | proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.png'], |
