Browse Source

Frozen: correctly parse _ and digits in keys

PUBLISHED_FROM=5a6810672e035048f0fc229c4f81f79a3521081d
Sergey Lyubka 9 years ago
parent
commit
71ccf536bd
2 changed files with 9 additions and 2 deletions
  1. 2 2
      frozen.c
  2. 7 0
      unit_test.c

+ 2 - 2
frozen.c

@@ -588,9 +588,9 @@ int json_vprintf(struct json_out *out, const char *fmt, va_list xap) {
         }
         }
       }
       }
       fmt += skip;
       fmt += skip;
-    } else if (is_alpha(*fmt)) {
+    } else if (*fmt == '_' || is_alpha(*fmt)) {
       len += out->printer(out, quote, 1);
       len += out->printer(out, quote, 1);
-      while (is_alpha(*fmt)) {
+      while (*fmt == '_' || is_alpha(*fmt) || is_digit(*fmt)) {
         len += out->printer(out, fmt, 1);
         len += out->printer(out, fmt, 1);
         fmt++;
         fmt++;
       }
       }

+ 7 - 0
unit_test.c

@@ -294,6 +294,13 @@ static const char *test_json_printf(void) {
     ASSERT(strcmp(buf, "ab 5") == 0);
     ASSERT(strcmp(buf, "ab 5") == 0);
   }
   }
 
 
+  {
+    struct json_out out = JSON_OUT_BUF(buf, sizeof(buf));
+    memset(buf, 0, sizeof(buf));
+    ASSERT(json_printf(&out, "a_b0: %d", 1) > 0);
+    ASSERT(strcmp(buf, "\"a_b0\": 1") == 0);
+  }
+
   return NULL;
   return NULL;
 }
 }