diff options
Diffstat (limited to 'source/Utility/JSON.cpp')
-rw-r--r-- | source/Utility/JSON.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/source/Utility/JSON.cpp b/source/Utility/JSON.cpp index 1520bc7c47ec7..9049f596ab9a5 100644 --- a/source/Utility/JSON.cpp +++ b/source/Utility/JSON.cpp @@ -22,7 +22,7 @@ using namespace lldb_private; std::string JSONString::json_string_quote_metachars(const std::string &s) { - if (s.find('"') == std::string::npos) + if (s.find_first_of("\\\n\"") == std::string::npos) return s; std::string output; @@ -30,8 +30,9 @@ std::string JSONString::json_string_quote_metachars(const std::string &s) { const char *s_chars = s.c_str(); for (size_t i = 0; i < s_size; i++) { unsigned char ch = *(s_chars + i); - if (ch == '"') { + if (ch == '"' || ch == '\\' || ch == '\n') { output.push_back('\\'); + if (ch == '\n') ch = 'n'; } output.push_back(ch); } |