From 40521e315fc8cc94837c1508dca94efeed939f82 Mon Sep 17 00:00:00 2001 From: Maxim Anisimov Date: Tue, 17 Sep 2019 07:53:21 +0300 Subject: mmcli: fix value escaping in new JSON output support Signed-off-by: Maxim Anisimov --- cli/mmcli-output.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'cli/mmcli-output.c') diff --git a/cli/mmcli-output.c b/cli/mmcli-output.c index 0b70a211..4fd9db38 100644 --- a/cli/mmcli-output.c +++ b/cli/mmcli-output.c @@ -1088,10 +1088,8 @@ dump_output_json (void) MmcF current_field = MMC_F_UNKNOWN; gchar **current_path = NULL; guint cur_dlen = 0; - GRegex *escape_regex; output_items = g_list_sort (output_items, (GCompareFunc) list_sort_by_keys); - escape_regex = g_regex_new ("'", G_REGEX_MULTILINE | G_REGEX_RAW, 0, NULL); g_print("{"); for (l = output_items; l; l = g_list_next (l)) { @@ -1135,7 +1133,7 @@ dump_output_json (void) gchar *escaped = NULL; if (single->value) - escaped = g_regex_replace_literal (escape_regex, single->value, -1, 0, "\"", 0, NULL); + escaped = g_strescape (single->value, "\v"); g_print ("\"%s\":\"%s\"", current_path[cur_dlen], escaped ? escaped : "--"); g_free (escaped); @@ -1149,7 +1147,7 @@ dump_output_json (void) for (i = 0; i < n; i++) { gchar *escaped; - escaped = g_regex_replace_literal (escape_regex, multiple->values[i], -1, 0, "\"", 0, NULL); + escaped = g_strescape (multiple->values[i], "\v"); g_print("\"%s\"", escaped); if (i < n - 1) g_print(","); @@ -1165,7 +1163,6 @@ dump_output_json (void) g_print("}\n"); g_strfreev (current_path); - g_regex_unref (escape_regex); } static void -- cgit v1.2.3-70-g09d2