diff options
-rw-r--r-- | llvm/include/llvm/ADT/StringExtras.h | 4 | ||||
-rw-r--r-- | llvm/lib/Support/StringExtras.cpp | 17 | ||||
-rw-r--r-- | llvm/test/tools/dsymutil/X86/darwin-bundle.test | 4 | ||||
-rw-r--r-- | llvm/tools/dsymutil/dsymutil.cpp | 25 |
4 files changed, 40 insertions, 10 deletions
diff --git a/llvm/include/llvm/ADT/StringExtras.h b/llvm/include/llvm/ADT/StringExtras.h index 5e69016f80f..9af536c8822 100644 --- a/llvm/include/llvm/ADT/StringExtras.h +++ b/llvm/include/llvm/ADT/StringExtras.h @@ -255,6 +255,10 @@ inline StringRef getOrdinalSuffix(unsigned Val) { /// it if it is not printable or if it is an escape char. void PrintEscapedString(StringRef Name, raw_ostream &Out); +/// Print each character of the specified string, escaping HTML special +/// characters. +void PrintHTMLEscaped(StringRef String, raw_ostream &Out); + /// printLowerCase - Print each character as lowercase if it is uppercase. void printLowerCase(StringRef String, raw_ostream &Out); diff --git a/llvm/lib/Support/StringExtras.cpp b/llvm/lib/Support/StringExtras.cpp index f4933150d28..d8f8ff4f604 100644 --- a/llvm/lib/Support/StringExtras.cpp +++ b/llvm/lib/Support/StringExtras.cpp @@ -68,6 +68,23 @@ void llvm::PrintEscapedString(StringRef Name, raw_ostream &Out) { } } +void llvm::PrintHTMLEscaped(StringRef String, raw_ostream &Out) { + for (char C : String) { + if (C == '&') + Out << "&"; + else if (C == '<') + Out << "<"; + else if (C == '>') + Out << ">"; + else if (C == '\"') + Out << """; + else if (C == '\'') + Out << "'"; + else + Out << C; + } +} + void llvm::printLowerCase(StringRef String, raw_ostream &Out) { for (const char C : String) Out << toLower(C); diff --git a/llvm/test/tools/dsymutil/X86/darwin-bundle.test b/llvm/test/tools/dsymutil/X86/darwin-bundle.test index e1117807a65..7f1224f30a1 100644 --- a/llvm/test/tools/dsymutil/X86/darwin-bundle.test +++ b/llvm/test/tools/dsymutil/X86/darwin-bundle.test @@ -8,7 +8,7 @@ RUN: cat %p/../Inputs/Info.plist > %t/Info.plist RUN: dsymutil -oso-prepend-path=%p/.. %t/basic.macho.x86_64 -o %t/dsymdest/basic.macho.x86_64.dSYM RUN: FileCheck %s --input-file %t/dsymdest/basic.macho.x86_64.dSYM/Contents/Info.plist -RUN: dsymutil -oso-prepend-path=%p/.. %t/basic.macho.x86_64 -toolchain "toolchain" -o %t/dsymdest/basic.macho.x86_64.dSYM +RUN: dsymutil -oso-prepend-path=%p/.. %t/basic.macho.x86_64 -toolchain "toolchain&and'some<symbols" -o %t/dsymdest/basic.macho.x86_64.dSYM RUN: FileCheck %s --input-file %t/dsymdest/basic.macho.x86_64.dSYM/Contents/Info.plist --check-prefix=CHECK --check-prefix=TOOLCHAIN CHECK: <?xml version="1.0" encoding="UTF-8"?> @@ -30,6 +30,6 @@ CHECK-NEXT: <string>2.0</string> CHECK-NEXT: <key>CFBundleVersion</key> CHECK-NEXT: <string>2</string> TOOLCHAIN: <key>Toolchain</key> -TOOLCHAIN-NEXT: <string>toolchain</string> +TOOLCHAIN-NEXT: <string>toolchain&and'some<symbols</string> CHECK: </dict> CHECK-NEXT: </plist> diff --git a/llvm/tools/dsymutil/dsymutil.cpp b/llvm/tools/dsymutil/dsymutil.cpp index 7487dd9694e..899c71e02d6 100644 --- a/llvm/tools/dsymutil/dsymutil.cpp +++ b/llvm/tools/dsymutil/dsymutil.cpp @@ -18,6 +18,7 @@ #include "MachOUtils.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" #include "llvm/DebugInfo/DIContext.h" @@ -193,16 +194,24 @@ static bool createPlistFile(llvm::StringRef Bin, llvm::StringRef BundleRoot) { << "\t\t<key>CFBundleSignature</key>\n" << "\t\t<string>\?\?\?\?</string>\n"; - if (!BI.OmitShortVersion()) - PL << "\t\t<key>CFBundleShortVersionString</key>\n" - << "\t\t<string>" << BI.ShortVersionStr << "</string>\n"; + if (!BI.OmitShortVersion()) { + PL << "\t\t<key>CFBundleShortVersionString</key>\n"; + PL << "\t\t<string>"; + PrintHTMLEscaped(BI.ShortVersionStr, PL); + PL << "</string>\n"; + } - PL << "\t\t<key>CFBundleVersion</key>\n" - << "\t\t<string>" << BI.VersionStr << "</string>\n"; + PL << "\t\t<key>CFBundleVersion</key>\n"; + PL << "\t\t<string>"; + PrintHTMLEscaped(BI.VersionStr, PL); + PL << "</string>\n"; - if (!Toolchain.empty()) - PL << "\t\t<key>Toolchain</key>\n" - << "\t\t<string>" << Toolchain << "</string>\n"; + if (!Toolchain.empty()) { + PL << "\t\t<key>Toolchain</key>\n"; + PL << "\t\t<string>"; + PrintHTMLEscaped(Toolchain, PL); + PL << "</string>\n"; + } PL << "\t</dict>\n" << "</plist>\n"; |