]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
formattable: fixes
authorYehuda Sadeh <yehuda@redhat.com>
Tue, 9 Jan 2018 09:30:37 +0000 (01:30 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Thu, 12 Apr 2018 22:38:37 +0000 (15:38 -0700)
Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/common/ceph_json.cc

index f43fce8bfa81547ed670e3e4458eeb8555f2af9f..656189dc0f7ad5be622ab63c0f6d49a989eb3793 100644 (file)
@@ -694,7 +694,16 @@ int JSONFormattable::set(const string& name, const string& val)
 
   JSONParser jp;
 
-  bool is_json = jp.parse(val.c_str(), val.size());
+  if (!jp.parse(val.c_str(), val.size())) {
+    /* can't parse, input is raw string */
+    if (!name.empty()) {
+      f->type = FMT_OBJ;
+      f = &f->obj[name];
+    }
+    f->type = FMT_STRING;
+    f->str = val;
+    return 0;
+  }
 
   for (auto i : tok) {
     vector<field_entity> v;
@@ -737,12 +746,7 @@ int JSONFormattable::set(const string& name, const string& val)
     }
   }
 
-  if (is_json) {
-    f->decode_json(&jp);
-  } else {
-    f->type = FMT_STRING;
-    f->str = val;
-  }
+  f->decode_json(&jp);
 
   return 0;
 }
@@ -763,7 +767,8 @@ int JSONFormattable::erase(const string& name)
       return ret;
     }
     for (auto vi : v) {
-      if (f->type == FMT_NONE) {
+      if (f->type == FMT_NONE ||
+          f->type == FMT_STRING) {
         if (vi.is_obj) {
           f->type = FMT_OBJ;
         } else {