Browse Source

Correctly handle `key: "%s"` formats

PUBLISHED_FROM=c033ba5d74609a964e4418fdef918afa1975dd0e
Sergey Lyubka 9 years ago
parent
commit
50c758bb1c
2 changed files with 8 additions and 1 deletions
  1. 1 1
      frozen.c
  2. 7 0
      unit_test.c

+ 1 - 1
frozen.c

@@ -467,7 +467,7 @@ int json_vprintf(struct json_out *out, const char *fmt, va_list xap) {
   va_copy(ap, xap);
   va_copy(ap, xap);
 
 
   while (*fmt != '\0') {
   while (*fmt != '\0') {
-    if (strchr(":, \r\n\t[]{}", *fmt) != NULL) {
+    if (strchr(":, \r\n\t[]{}\"", *fmt) != NULL) {
       len += out->printer(out, fmt, 1);
       len += out->printer(out, fmt, 1);
       fmt++;
       fmt++;
     } else if (fmt[0] == '%') {
     } else if (fmt[0] == '%') {

+ 7 - 0
unit_test.c

@@ -280,6 +280,13 @@ static const char *test_json_printf(void) {
     ASSERT(strcmp(buf, result) == 0);
     ASSERT(strcmp(buf, result) == 0);
   }
   }
 
 
+  {
+    struct json_out out = JSON_OUT_BUF(buf, sizeof(buf));
+    memset(buf, 0, sizeof(buf));
+    ASSERT(json_printf(&out, "{a: \"%s\"}", "b") > 0);
+    ASSERT(strcmp(buf, "{\"a\": \"b\"}") == 0);
+  }
+
   return NULL;
   return NULL;
 }
 }