Improve JSON detection: strip both ends, check matching brackets, use full content
This commit is contained in:
@@ -90,10 +90,13 @@ def detect_type(
|
|||||||
return EXTENSION_MAP[suffix]
|
return EXTENSION_MAP[suffix]
|
||||||
|
|
||||||
if content is not None:
|
if content is not None:
|
||||||
stripped = content.lstrip()
|
stripped = content.strip()
|
||||||
if stripped and stripped[0] in ("{", "["):
|
if stripped and (
|
||||||
|
(stripped[0] == "{" and stripped[-1] == "}")
|
||||||
|
or (stripped[0] == "[" and stripped[-1] == "]")
|
||||||
|
):
|
||||||
try:
|
try:
|
||||||
json.loads(stripped[:1000])
|
json.loads(stripped)
|
||||||
return "json"
|
return "json"
|
||||||
except (json.JSONDecodeError, ValueError):
|
except (json.JSONDecodeError, ValueError):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user