Skip to content
Snippets Groups Projects
Commit 8ff57c58 authored by Julien (jvoisin) Voisin's avatar Julien (jvoisin) Voisin
Browse files

Do not display control characters in output

Kudos to Sherry Taylor for reporting this issue :hearts:
parent 04bb8c8c
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ import sys ...@@ -6,6 +6,7 @@ import sys
import mimetypes import mimetypes
import argparse import argparse
import logging import logging
import unicodedata
try: try:
from libmat2 import parser_factory, UNSUPPORTED_EXTENSIONS from libmat2 import parser_factory, UNSUPPORTED_EXTENSIONS
...@@ -83,6 +84,15 @@ def __print_meta(filename: str, metadata: dict, depth: int=1): ...@@ -83,6 +84,15 @@ def __print_meta(filename: str, metadata: dict, depth: int=1):
if isinstance(v, dict): if isinstance(v, dict):
__print_meta(k, v, depth+1) __print_meta(k, v, depth+1)
continue continue
# Remove control characters
# We might use 'Cc' instead of 'C', but better safe than sorry
# https://www.unicode.org/reports/tr44/#GC_Values_Table
try:
v = ''.join(ch for ch in v if not unicodedata.category(ch).startswith('C'))
except TypeError:
pass # for things that aren't iterable
try: # FIXME this is ugly. try: # FIXME this is ugly.
print(padding + " %s: %s" % (k, v)) print(padding + " %s: %s" % (k, v))
except UnicodeEncodeError: except UnicodeEncodeError:
......
...@@ -121,7 +121,7 @@ class TestGetMeta(unittest.TestCase): ...@@ -121,7 +121,7 @@ class TestGetMeta(unittest.TestCase):
proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.pdf'], proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.pdf'],
stdout=subprocess.PIPE) stdout=subprocess.PIPE)
stdout, _ = proc.communicate() stdout, _ = proc.communicate()
self.assertIn(b'producer: pdfTeX-1.40.14', stdout) self.assertIn(b'Producer: pdfTeX-1.40.14', stdout)
def test_png(self): def test_png(self):
proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.png'], proc = subprocess.Popen(mat2_binary + ['--show', './tests/data/dirty.png'],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment