summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/source/Core/StructuredData.cpp2
-rw-r--r--lldb/unittests/Core/CMakeLists.txt1
-rw-r--r--lldb/unittests/Core/StructuredDataTest.cpp32
3 files changed, 34 insertions, 1 deletions
diff --git a/lldb/source/Core/StructuredData.cpp b/lldb/source/Core/StructuredData.cpp
index 3866861b8c1..46be7828f62 100644
--- a/lldb/source/Core/StructuredData.cpp
+++ b/lldb/source/Core/StructuredData.cpp
@@ -264,7 +264,7 @@ void StructuredData::String::Dump(Stream &s, bool pretty_print) const {
const size_t strsize = m_value.size();
for (size_t i = 0; i < strsize; ++i) {
char ch = m_value[i];
- if (ch == '"')
+ if (ch == '"' || ch == '\\')
quoted.push_back('\\');
quoted.push_back(ch);
}
diff --git a/lldb/unittests/Core/CMakeLists.txt b/lldb/unittests/Core/CMakeLists.txt
index 8ab43d666cf..9ec51755ea9 100644
--- a/lldb/unittests/Core/CMakeLists.txt
+++ b/lldb/unittests/Core/CMakeLists.txt
@@ -3,4 +3,5 @@ add_lldb_unittest(LLDBCoreTests
BroadcasterTest.cpp
DataExtractorTest.cpp
ScalarTest.cpp
+ StructuredDataTest.cpp
)
diff --git a/lldb/unittests/Core/StructuredDataTest.cpp b/lldb/unittests/Core/StructuredDataTest.cpp
new file mode 100644
index 00000000000..8e10d571fbf
--- /dev/null
+++ b/lldb/unittests/Core/StructuredDataTest.cpp
@@ -0,0 +1,32 @@
+//===-- StructuredDataTest.cpp ----------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+
+#include "lldb/Core/StructuredData.h"
+#include "lldb/Core/StreamString.h"
+
+#include "llvm/Support/MachO.h"
+
+using namespace lldb;
+using namespace lldb_private;
+
+TEST(StructuredDataTest, StringDump) {
+ std::pair<llvm::StringRef, llvm::StringRef> TestCases[] = {
+ { R"(asdfg)", R"("asdfg")" },
+ { R"(as"df)", R"("as\"df")" },
+ { R"(as\df)", R"("as\\df")" },
+ };
+ for(auto P : TestCases) {
+ StreamString S;
+ const bool pretty_print = false;
+ StructuredData::String(P.first).Dump(S, pretty_print);
+ EXPECT_EQ(P.second, S.GetString());
+ }
+}
OpenPOWER on IntegriCloud