llvm.org GIT mirror llvm / e22dca5
[dsymutil] Escape HTML special characters in plist. When printing string in the Plist, we weren't escaping the characters which lead to invalid XML. This patch adds the escape logic to StringExtras. rdar://39785334 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@333565 91177308-0d34-0410-b5e6-96231b3b80d8 Jonas Devlieghere 2 years ago
4 changed file(s) with 42 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
254254 /// it if it is not printable or if it is an escape char.
255255 void PrintEscapedString(StringRef Name, raw_ostream &Out);
256256
257 /// Print each character of the specified string, escaping HTML special
258 /// characters.
259 void PrintHTMLEscaped(StringRef String, raw_ostream &Out);
260
257261 /// printLowerCase - Print each character as lowercase if it is uppercase.
258262 void printLowerCase(StringRef String, raw_ostream &Out);
259263
6767 }
6868 }
6969
70 void llvm::PrintHTMLEscaped(StringRef String, raw_ostream &Out) {
71 for (char C : String) {
72 if (C == '&')
73 Out << "&";
74 else if (C == '<')
75 Out << "<";
76 else if (C == '>')
77 Out << ">";
78 else if (C == '\"')
79 Out << """;
80 else if (C == '\'')
81 Out << "'";
82 else
83 Out << C;
84 }
85 }
86
7087 void llvm::printLowerCase(StringRef String, raw_ostream &Out) {
7188 for (const char C : String)
7289 Out << toLower(C);
77 RUN: dsymutil -oso-prepend-path=%p/.. %t/basic.macho.x86_64 -o %t/dsymdest/basic.macho.x86_64.dSYM
88 RUN: FileCheck %s --input-file %t/dsymdest/basic.macho.x86_64.dSYM/Contents/Info.plist
99
10 RUN: dsymutil -oso-prepend-path=%p/.. %t/basic.macho.x86_64 -toolchain "toolchain" -o %t/dsymdest/basic.macho.x86_64.dSYM
10 RUN: dsymutil -oso-prepend-path=%p/.. %t/basic.macho.x86_64 -toolchain "toolchain&and'some" -o %t/dsymdest/basic.macho.x86_64.dSYM
1111 RUN: FileCheck %s --input-file %t/dsymdest/basic.macho.x86_64.dSYM/Contents/Info.plist --check-prefix=CHECK --check-prefix=TOOLCHAIN
1212
1313 CHECK:
2929 CHECK-NEXT: CFBundleVersion
3030 CHECK-NEXT: 2
3131 TOOLCHAIN: Toolchain
32 TOOLCHAIN-NEXT: toolchain
32 TOOLCHAIN-NEXT: toolchain&and'some<symbols
3333 CHECK:
3434 CHECK-NEXT:
1717 #include "MachOUtils.h"
1818 #include "llvm/ADT/SmallString.h"
1919 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/StringExtras.h"
2021 #include "llvm/ADT/StringRef.h"
2122 #include "llvm/ADT/Triple.h"
2223 #include "llvm/DebugInfo/DIContext.h"
192193 << "\t\tCFBundleSignature\n"
193194 << "\t\t\?\?\?\?\n";
194195
195 if (!BI.OmitShortVersion())
196 PL << "\t\tCFBundleShortVersionString\n"
197 << "\t\t" << BI.ShortVersionStr << "\n";
198
199 PL << "\t\tCFBundleVersion\n"
200 << "\t\t" << BI.VersionStr << "\n";
201
202 if (!Toolchain.empty())
203 PL << "\t\tToolchain\n"
204 << "\t\t" << Toolchain << "\n";
196 if (!BI.OmitShortVersion()) {
197 PL << "\t\tCFBundleShortVersionString\n";
198 PL << "\t\t";
199 PrintHTMLEscaped(BI.ShortVersionStr, PL);
200 PL << "\n";
201 }
202
203 PL << "\t\tCFBundleVersion\n";
204 PL << "\t\t";
205 PrintHTMLEscaped(BI.VersionStr, PL);
206 PL << "\n";
207
208 if (!Toolchain.empty()) {
209 PL << "\t\tToolchain\n";
210 PL << "\t\t";
211 PrintHTMLEscaped(Toolchain, PL);
212 PL << "\n";
213 }
205214
206215 PL << "\t\n"
207216 << "\n";