json: Make json_equal() compare objects correctly.
authorBen Pfaff <blp@nicira.com>
Fri, 6 Nov 2009 20:24:44 +0000 (12:24 -0800)
committerBen Pfaff <blp@nicira.com>
Fri, 6 Nov 2009 20:26:22 +0000 (12:26 -0800)
The previous code checked only that JSON objects have members with the
same names.  This commit makes json_equal() also check that like-named
members have the same values.

lib/json.c

index dfd6b84..cdcfba5 100644 (file)
@@ -500,14 +500,15 @@ json_hash(const struct json *json, size_t basis)
 static bool
 json_equal_object(const struct shash *a, const struct shash *b)
 {
-    struct shash_node *node;
+    struct shash_node *a_node;
 
     if (shash_count(a) != shash_count(b)) {
         return false;
     }
 
-    SHASH_FOR_EACH (node, a) {
-        if (!shash_find(b, node->name)) {
+    SHASH_FOR_EACH (a_node, a) {
+        struct shash_node *b_node = shash_find(b, a_node->name);
+        if (!b_node || !json_equal(a_node->data, b_node->data)) {
             return false;
         }
     }