src/json.c

changeset 1548
12315ee158ad
parent 1547
12da0654e4a9
--- a/src/json.c	Sat Dec 06 16:30:11 2025 +0100
+++ b/src/json.c	Sat Dec 06 17:51:08 2025 +0100
@@ -1178,19 +1178,17 @@
                 cxstring key = cx_strn(member->key->data, member->key->len);
                 cxmutstr name = escape_string(key, settings->escape_slash);
                 actual += wfunc(name.ptr, 1, name.length, target);
-                if (name.ptr != key.ptr) {
-                    cx_strfree(&name);
-                }
                 actual += wfunc("\"", 1, 1, target);
                 const char *obj_name_sep = ": ";
                 if (settings->pretty) {
                     actual += wfunc(obj_name_sep, 1, 2, target);
-                    // FIXME: is this really correct? should be the (escaped) name.length
-                    expected += 4 + key.length;
+                    expected += 4 + name.length;
                 } else {
                     actual += wfunc(obj_name_sep, 1, 1, target);
-                    // FIXME: is this really correct? should be the (escaped) name.length
-                    expected += 3 + key.length;
+                    expected += 3 + name.length;
+                }
+                if (name.ptr != key.ptr) {
+                    cx_strfree(&name);
                 }
 
                 // the value
@@ -1253,11 +1251,11 @@
             cxmutstr str = escape_string(cx_strcast(value->string),
                 settings->escape_slash);
             actual += wfunc(str.ptr, 1, str.length, target);
+            actual += wfunc("\"", 1, 1, target);
+            expected += 2 + str.length;
             if (str.ptr != value->string.ptr) {
                 cx_strfree(&str);
             }
-            actual += wfunc("\"", 1, 1, target);
-            expected += 2 + value->string.length;
             break;
         }
         case CX_JSON_NUMBER: {

mercurial