Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac2359f

Browse files
committed
Patch of potential silent bug (digits charset)
1 parent ff5bdbe commit ac2359f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

lib/core/common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,11 +1649,11 @@ def getFileType(filePath):
16491649
"""
16501650

16511651
try:
1652-
_ = magic.from_file(filePath)
1652+
desc = magic.from_file(filePath) or ""
16531653
except:
16541654
return "unknown"
16551655

1656-
return "text" if "ASCII" in _ or "text" in _ else "binary"
1656+
return "text" if any(_ in desc.lower() for _ in ("ascii", "text")) else "binary"
16571657

16581658
def getCharset(charsetType=None):
16591659
"""
@@ -1669,14 +1669,14 @@ def getCharset(charsetType=None):
16691669
if charsetType is None:
16701670
asciiTbl.extend(xrange(0, 128))
16711671

1672-
# 0 or 1
1672+
# Binary
16731673
elif charsetType == CHARSET_TYPE.BINARY:
16741674
asciiTbl.extend([0, 1])
16751675
asciiTbl.extend(xrange(47, 50))
16761676

16771677
# Digits
16781678
elif charsetType == CHARSET_TYPE.DIGITS:
1679-
asciiTbl.extend([0, 1])
1679+
asciiTbl.extend([0, 9])
16801680
asciiTbl.extend(xrange(47, 58))
16811681

16821682
# Hexadecimal

0 commit comments

Comments
 (0)