diff options
| author | Charles Giessen <charles@lunarg.com> | 2022-11-30 16:51:02 -0600 |
|---|---|---|
| committer | Charles Giessen <46324611+charles-lunarg@users.noreply.github.com> | 2022-11-30 19:22:24 -0600 |
| commit | 6361ae332cd31aaea0ef1494e2102e65b962afea (patch) | |
| tree | 859450956c9f51a7d41c2edcdefb21649a19b392 | |
| parent | 0a122e62b8f62dd52b7731b58c1385312f2834aa (diff) | |
| download | usermoji-6361ae332cd31aaea0ef1494e2102e65b962afea.tar.xz | |
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.
| -rw-r--r-- | vulkaninfo/outputprinter.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/vulkaninfo/outputprinter.h b/vulkaninfo/outputprinter.h index f77df3b7..35a60c56 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. // <https://www.json.org/json-en.html> 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]; |
