Commit 2a758d3d authored by Chris Lamb's avatar Chris Lamb 💬

Do some cheap fuzzy parsing to detect JSON files not named .json. (re. #888112)

parent 9bcbb517
......@@ -26,14 +26,16 @@ from .utils.file import File
class JSONFile(File):
FILE_EXTENSION_SUFFIX = '.json'
@classmethod
def recognizes(cls, file):
if not super().recognizes(file):
return False
with open(file.path) as f:
# Try fuzzy matching for JSON files
if not file.name.endswith('.json') and \
file.magic_file_type.startswith('ASCII text'):
if '{' not in f.read(10):
return False
f.seek(0)
try:
file.parsed = json.load(
f,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment