From 6361ae332cd31aaea0ef1494e2102e65b962afea Mon Sep 17 00:00:00 2001 From: Charles Giessen Date: Wed, 30 Nov 2022 16:51:02 -0600 Subject: [PATCH] vulkaninfo: Fix quoting strings in json output When adding a value_description, the json output would incorrectly quote the PrintKeyString output, leading to invalid json being generated. --- vulkaninfo/outputprinter.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vulkaninfo/outputprinter.h b/vulkaninfo/outputprinter.h index f77df3b..35a60c5 100644 --- a/vulkaninfo/outputprinter.h +++ b/vulkaninfo/outputprinter.h @@ -548,7 +548,12 @@ class Printer { break; case (OutputType::json): case (OutputType::vkconfig_output): - PrintKeyValue(key, std::string("\"") + EscapeJSONCString(value) + "\""); + if (!value_description.empty()) { + // PrintKeyValue adds the necessary quotes when printing with a value description set + PrintKeyValue(key, EscapeJSONCString(value)); + } else { + PrintKeyValue(key, std::string("\"") + EscapeJSONCString(value) + "\""); + } break; default: break; @@ -731,7 +736,7 @@ class Printer { // Replace special characters in strings with their escaped versions. // std::string EscapeJSONCString(std::string string) { - if (output_type != OutputType::json) return string; + if (output_type == OutputType::text || output_type == OutputType::html) return string; std::string out{}; for (size_t i = 0; i < string.size(); i++) { char c = string[i]; -- 2.7.4