Use utf8 as default encoding, if encoding cannot be guessed.

This commit is contained in:
Achim D. Brucker 2019-08-21 10:23:53 +01:00
parent 377519c27b
commit 828b77e035
1 changed files with 5 additions and 2 deletions

View File

@ -95,8 +95,11 @@ def main():
if fhandle is not sys.stdin.buffer:
fhandle.close()
content = data.decode(encoding=chardet.detect(data)['encoding'],
errors="replace")
encoding = chardet.detect(data)['encoding']
if encoding:
content = data.decode(encoding=encoding, errors="replace")
else:
content = data.decode(encoding='utf8', errors="replace")
if args.html:
content = unsanitize_html(content)