From b65dc74427864dee94ce58949efc140525410377 Mon Sep 17 00:00:00 2001 From: nickomodee <144nre2@gmail.com> Date: Tue, 24 Jun 2025 03:12:46 +1200 Subject: [PATCH] Fix: incorrect list truncation in fast mode when comma is not followed by space Fixes an edge case in `loads(..., ALL & ~STR, )` where an unterminated string inside a list caused early truncation if commas were used without a space after. The issue was from an off by one error in the upper bound of `rfind()` which excluded the last string element unless a space followed the comma. Before: `loads('{"key": ["a", "b", "c","d', ALL & ~STR)` -> `{"key": ["a", "b"]}` After: `loads('{"key": ["a", "b", "c", "d', ALL & ~STR)` -> `{"key": ["a", "b", "c", "d"]}` This change adjusts the search range in `rfind()` to correctly detect the last comma, even when it is not followed by a whitespace. --- src/partial_json_parser/core/myelin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/partial_json_parser/core/myelin.py b/src/partial_json_parser/core/myelin.py index 963867c..69bcd82 100644 --- a/src/partial_json_parser/core/myelin.py +++ b/src/partial_json_parser/core/myelin.py @@ -120,7 +120,7 @@ def truncate_before_last_key_start(container_start: int, last_string_end: int, s # { "k return json_string[: stack[-1][0] + 1], join_closing_tokens(stack) - last_comma = json_string.rfind(",", max(stack[-1][0], last_string_end) + 1, last_string_start - 1) + last_comma = json_string.rfind(",", max(stack[-1][0], last_string_end) + 1, last_string_start) if last_comma != -1: # { "key": "v", "k # { "key": 123, "k