Skip to content
Snippets Groups Projects
Commit 4ba7e6c8 authored by Marek Marczykowski-Górecki's avatar Marek Marczykowski-Górecki Committed by Chris Lamb
Browse files

comparators/json: Try fuzzy matching for non-text files too. (Closes: #909122)


Non-text files have even less change being json files, so this fuzzy early
elimination is even more useful for them.  In particular, it avoids loading
large files (like ISO images) just to discover it isn't a JSON format.

Signed-off-by: Chris Lamb's avatarChris Lamb <lamby@debian.org>
parent 34898e40
No related branches found
No related tags found
No related merge requests found
Pipeline #19356 failed
......@@ -37,11 +37,7 @@ class JSONFile(File):
def recognizes(cls, file):
with open(file.path, 'rb') as f:
# Try fuzzy matching for JSON files
is_text = any(
file.magic_file_type.startswith(x)
for x in ('ASCII text', 'UTF-8 Unicode text')
)
if is_text and not file.name.endswith('.json'):
if not file.name.endswith('.json'):
buf = f.read(10)
if not any(x in buf for x in b'{['):
return False
......
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