From ac2359f8df688a9fcf14410c45532f492e4865d9 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 31 Oct 2017 10:03:23 +0100 Subject: [PATCH] Patch of potential silent bug (digits charset) --- lib/core/common.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index af99af98e..576b8d5c2 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -1649,11 +1649,11 @@ def getFileType(filePath): """ try: - _ = magic.from_file(filePath) + desc = magic.from_file(filePath) or "" except: return "unknown" - return "text" if "ASCII" in _ or "text" in _ else "binary" + return "text" if any(_ in desc.lower() for _ in ("ascii", "text")) else "binary" def getCharset(charsetType=None): """ @@ -1669,14 +1669,14 @@ def getCharset(charsetType=None): if charsetType is None: asciiTbl.extend(xrange(0, 128)) - # 0 or 1 + # Binary elif charsetType == CHARSET_TYPE.BINARY: asciiTbl.extend([0, 1]) asciiTbl.extend(xrange(47, 50)) # Digits elif charsetType == CHARSET_TYPE.DIGITS: - asciiTbl.extend([0, 1]) + asciiTbl.extend([0, 9]) asciiTbl.extend(xrange(47, 58)) # Hexadecimal