src/json.c

changeset 1139
7dfa5bcf39ee
parent 1132
b7fea9b2874c
--- a/src/json.c	Wed Jan 22 20:36:10 2025 +0100
+++ b/src/json.c	Wed Jan 22 21:02:46 2025 +0100
@@ -263,6 +263,9 @@
     CxJsonTokenType ttype = json->uncompleted.tokentype;
     size_t token_part_start = json->buffer.pos;
 
+    bool escape_end_of_string = ttype == CX_JSON_TOKEN_STRING
+        && json->uncompleted.content.ptr[json->uncompleted.content.length-1] == '\\';
+
     for (size_t i = json->buffer.pos; i < json->buffer.size; i++) {
         char c = json->buffer.space[i];
         if (ttype != CX_JSON_TOKEN_STRING) {
@@ -301,8 +304,8 @@
             }
         } else {
             // currently inside a string
-            if (json->tokenizer_escape) {
-                json->tokenizer_escape = false;
+            if (escape_end_of_string) {
+                escape_end_of_string = false;
             } else {
                 if (c == '"') {
                     *result = token_create(json, true, token_part_start, i + 1);
@@ -312,7 +315,7 @@
                     json->buffer.pos = i + 1;
                     return CX_JSON_NO_ERROR;
                 } else if (c == '\\') {
-                    json->tokenizer_escape = true;
+                    escape_end_of_string = true;
                 }
             }
         }

mercurial