From 217feab7dea98756935bd488774cd9130332a185 Mon Sep 17 00:00:00 2001 From: Yunxiao Xu Date: Wed, 1 Apr 2026 23:51:41 -0700 Subject: [PATCH] Improve JSON detection: strip both ends, check matching brackets, use full content --- src/rp/detect.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rp/detect.py b/src/rp/detect.py index e439c16..fd3dc00 100644 --- a/src/rp/detect.py +++ b/src/rp/detect.py @@ -90,10 +90,13 @@ def detect_type( return EXTENSION_MAP[suffix] if content is not None: - stripped = content.lstrip() - if stripped and stripped[0] in ("{", "["): + stripped = content.strip() + if stripped and ( + (stripped[0] == "{" and stripped[-1] == "}") + or (stripped[0] == "[" and stripped[-1] == "]") + ): try: - json.loads(stripped[:1000]) + json.loads(stripped) return "json" except (json.JSONDecodeError, ValueError): pass