From 6782ffb78565e950243d62479bc2fedfe529e256 Mon Sep 17 00:00:00 2001 From: Siddharth Goyal Date: Thu, 20 Nov 2025 02:50:09 +0530 Subject: [PATCH 1/3] made valid json - added case for double quotes as well --- src/toon_format/decoder.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/toon_format/decoder.py b/src/toon_format/decoder.py index 90f0849..bb08e6e 100644 --- a/src/toon_format/decoder.py +++ b/src/toon_format/decoder.py @@ -74,10 +74,12 @@ def parse_primitive(token: str) -> JsonValue: token = token.strip() # Quoted string - if token.startswith(DOUBLE_QUOTE): - if not token.endswith(DOUBLE_QUOTE) or len(token) < 2: + if not token.endswith(DOUBLE_QUOTE) or len(token) < 2: + if not match_quotes(token): raise ToonDecodeError("Unterminated string: missing closing quote") - return unescape_string(token[1:-1]) + else: + print(f"Malformed double quoted string : '{token}'") + return unescape_string(token) # Boolean and null literals if is_boolean_or_null_literal(token): @@ -786,3 +788,21 @@ def decode_list_array( raise ToonDecodeError(f"Expected {expected_length} items, but got {len(result)}") return result, i + +def match_quotes(line: str) -> bool: + """Check if quotes in the line are properly matched. + + Args: + line: Line content + Returns: + True if quotes are matched, False otherwise + """ + + double_quote_balance = 0 + + for char in line: + + if(char == DOUBLE_QUOTE): + double_quote_balance += 1 + + return (double_quote_balance % 2 == 0) \ No newline at end of file From e4946db5afee178994fc190c93261b6e629de0f4 Mon Sep 17 00:00:00 2001 From: Siddharth Goyal Date: Thu, 20 Nov 2025 02:52:16 +0530 Subject: [PATCH 2/3] made it clear for start & end quotes --- src/toon_format/decoder.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/toon_format/decoder.py b/src/toon_format/decoder.py index bb08e6e..a7c1beb 100644 --- a/src/toon_format/decoder.py +++ b/src/toon_format/decoder.py @@ -74,12 +74,14 @@ def parse_primitive(token: str) -> JsonValue: token = token.strip() # Quoted string - if not token.endswith(DOUBLE_QUOTE) or len(token) < 2: - if not match_quotes(token): - raise ToonDecodeError("Unterminated string: missing closing quote") - else: - print(f"Malformed double quoted string : '{token}'") - return unescape_string(token) + if token.startswith(DOUBLE_QUOTE): + if not token.endswith(DOUBLE_QUOTE) or len(token) < 2: + if not match_quotes(token): + raise ToonDecodeError("Unterminated string: missing closing quote") + else: + print(f"Malformed double quoted string : '{token}'") + return unescape_string(token) + return unescape_string(token[1:-1]) # Boolean and null literals if is_boolean_or_null_literal(token): From 88411ce60fb882520dee78025a0aa52f04511bcc Mon Sep 17 00:00:00 2001 From: Siddharth Goyal Date: Thu, 20 Nov 2025 02:53:34 +0530 Subject: [PATCH 3/3] removed garbage code --- src/toon_format/decoder.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/toon_format/decoder.py b/src/toon_format/decoder.py index a7c1beb..580ec80 100644 --- a/src/toon_format/decoder.py +++ b/src/toon_format/decoder.py @@ -79,7 +79,6 @@ def parse_primitive(token: str) -> JsonValue: if not match_quotes(token): raise ToonDecodeError("Unterminated string: missing closing quote") else: - print(f"Malformed double quoted string : '{token}'") return unescape_string(token) return unescape_string(token[1:-1])