]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
json_writer: fix builtin test code
authorStephen Hemminger <stephen@networkplumber.org>
Fri, 10 Apr 2026 22:46:27 +0000 (15:46 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Fri, 10 Apr 2026 22:46:27 +0000 (15:46 -0700)
The code under #ifdef was not generating valid JSON
and it is missing test for control characters.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
lib/json_writer.c

index 7202621ea22ac57c63d5f8e297340b87b58b9a95..d4a1c72ba86c023d8e911b07743dc6cfa32816c0 100644 (file)
@@ -369,7 +369,7 @@ int main(int argc, char **argv)
        jsonw_null_field(wr, "my_null");
 
        jsonw_name(wr, "special chars");
-       jsonw_start_array(wr);
+       jsonw_start_object(wr);
        jsonw_string_field(wr, "slash", "/");
        jsonw_string_field(wr, "newline", "\n");
        jsonw_string_field(wr, "tab", "\t");
@@ -377,7 +377,14 @@ int main(int argc, char **argv)
        jsonw_string_field(wr, "quote", "\"");
        jsonw_string_field(wr, "tick", "\'");
        jsonw_string_field(wr, "backslash", "\\");
-       jsonw_end_array(wr);
+       jsonw_end_object(wr);
+
+       jsonw_name(wr, "control chars");
+       jsonw_start_object(wr);
+       jsonw_string_field(wr, "bell", "\a");
+       jsonw_string_field(wr, "esc", "\033");
+       jsonw_string_field(wr, "del", "\177");
+       jsonw_end_object(wr);
 
        jsonw_end_object(wr);