summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/YAMLTraits.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Support/YAMLTraits.cpp')
-rw-r--r--llvm/lib/Support/YAMLTraits.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp
index ae7f7dcb0d0..1a6adbf559b 100644
--- a/llvm/lib/Support/YAMLTraits.cpp
+++ b/llvm/lib/Support/YAMLTraits.cpp
@@ -510,8 +510,16 @@ void Output::endBitSetScalar() {
void Output::scalarString(StringRef &S) {
this->newLineCheck();
- if (S.find('\n') == StringRef::npos) {
- // No embedded new-line chars, just print string.
+
+ if (S.empty()) {
+ // Print '' for the empty string because leaving the field empty is not
+ // allowed.
+ this->outputUpToEndOfLine("''");
+ return;
+ }
+ if (!strchr("'`@\"", S.front()) && S.find('\n') == StringRef::npos) {
+ // Plain string cannot start with double quote or single quote. Backquote
+ // and atsign are reserved characters. Newline is not allowed.
this->outputUpToEndOfLine(S);
return;
}
OpenPOWER on IntegriCloud