@@ -193,7 +193,7 @@ def parse_string(self: "JSONParser") -> JSONReturnType:
193193 not self .stream_stable
194194 and char == "]"
195195 and ContextValues .ARRAY in self .context .context
196- and string_acc [- 1 ] != rstring_delimiter
196+ and ( not string_acc or string_acc [- 1 ] != rstring_delimiter )
197197 ):
198198 # We found the end of an array and we are in array context
199199 # So let's check if we find a rstring_delimiter forward otherwise end early
@@ -226,9 +226,9 @@ def parse_string(self: "JSONParser") -> JSONReturnType:
226226 self .index += 1
227227 char = self .get_char_at ()
228228 # Unclosed string ends with a \ character. This character is ignored if stream_stable = True.
229- if self .stream_stable and not char and string_acc [- 1 ] == "\\ " :
229+ if self .stream_stable and not char and string_acc and string_acc [- 1 ] == "\\ " :
230230 string_acc = string_acc [:- 1 ]
231- if char and string_acc [- 1 ] == "\\ " :
231+ if char and string_acc and string_acc [- 1 ] == "\\ " :
232232 # This is a special case, if people use real strings this might happen
233233 self .log ("Found a stray escape sequence, normalizing it" )
234234 if char in [rstring_delimiter , "t" , "n" , "r" , "b" , "\\ " ]:
@@ -237,7 +237,7 @@ def parse_string(self: "JSONParser") -> JSONReturnType:
237237 string_acc += escape_seqs .get (char , char )
238238 self .index += 1
239239 char = self .get_char_at ()
240- while char and string_acc [- 1 ] == "\\ " and char in [rstring_delimiter , "\\ " ]:
240+ while char and string_acc and string_acc [- 1 ] == "\\ " and char in [rstring_delimiter , "\\ " ]:
241241 # this is a bit of a special case, if I don't do this it will close the loop or create a train of \\
242242 # I don't love it though
243243 string_acc = string_acc [:- 1 ] + char
@@ -289,7 +289,7 @@ def parse_string(self: "JSONParser") -> JSONReturnType:
289289 )
290290 break
291291 # ChatGPT sometimes forget to quote stuff in html tags or markdown, so we do this whole thing here
292- if char == rstring_delimiter and string_acc [- 1 ] != "\\ " :
292+ if char == rstring_delimiter and string_acc and string_acc [- 1 ] != "\\ " :
293293 # Special case here, in case of double quotes one after another
294294 if doubled_quotes and self .get_char_at (1 ) == rstring_delimiter :
295295 self .log ("While parsing a string, we found a doubled quote, ignoring it" )
0 commit comments