From f288c56a51c852dbae6604455e3ce6386e328095 Mon Sep 17 00:00:00 2001 From: Ben Langmuir Date: Thu, 17 Apr 2014 03:31:02 +0000 Subject: [PATCH] When writing YAML in libclang, use yaml::escape instead of write_escaped The YAMLParser has its own escaped string representation, and does not handle octal escape sequences. When writing the virtual file system to a YAML file, use yaml::escape(). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206443 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/libclang/BuildSystem.cpp | 8 ++++---- unittests/libclang/LibclangTest.cpp | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/tools/libclang/BuildSystem.cpp b/tools/libclang/BuildSystem.cpp index 89c6e91d23..c9d3c55327 100644 --- a/tools/libclang/BuildSystem.cpp +++ b/tools/libclang/BuildSystem.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/TimeValue.h" #include "llvm/Support/raw_ostream.h" +#include "llvm/Support/YAMLParser.h" using namespace clang; using namespace llvm::sys; @@ -147,10 +148,9 @@ private: OS.indent(Indent) << "{\n"; Indent += 2; OS.indent(Indent) << "'type': 'file',\n"; - OS.indent(Indent) << "'name': \""; - OS.write_escaped(VName) << "\",\n"; - OS.indent(Indent) << "'external-contents': \""; - OS.write_escaped(Entry.RPath) << "\"\n"; + OS.indent(Indent) << "'name': \"" << llvm::yaml::escape(VName) << "\",\n"; + OS.indent(Indent) << "'external-contents': \"" + << llvm::yaml::escape(Entry.RPath) << "\"\n"; Indent -= 2; OS.indent(Indent) << '}'; if (Entries.empty()) { diff --git a/unittests/libclang/LibclangTest.cpp b/unittests/libclang/LibclangTest.cpp index 64128f158f..e6b32b001d 100644 --- a/unittests/libclang/LibclangTest.cpp +++ b/unittests/libclang/LibclangTest.cpp @@ -84,6 +84,27 @@ TEST(libclang, VirtualFileOverlay) { TestVFO T(contents); T.map("/path/virtual/foo.h", "/real/foo.h"); } + { + const char *contents = + "{\n" + " 'version': 0,\n" + " 'roots': [\n" + " {\n" + " 'type': 'directory',\n" + " 'name': \"/path/virtual\",\n" + " 'contents': [\n" + " {\n" + " 'type': 'file',\n" + " 'name': \"\\u2602.h\",\n" + " 'external-contents': \"/real/\\u2602.h\"\n" + " }\n" + " ]\n" + " }\n" + " ]\n" + "}\n"; + TestVFO T(contents); + T.map("/path/virtual/☂.h", "/real/☂.h"); + } { TestVFO T(NULL); T.mapError("/path/./virtual/../foo.h", "/real/foo.h", -- 2.40.0