[llvm] r323097 - [YAML] Plain scalars can not begin with most indicators.
Haojian Wu via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 22 02:20:48 PST 2018
Author: hokein
Date: Mon Jan 22 02:20:48 2018
New Revision: 323097
URL: http://llvm.org/viewvc/llvm-project?rev=323097&view=rev
Log:
[YAML] Plain scalars can not begin with most indicators.
Summary:
Discovered when clangd loads YAML symbols, some symbol documentations
start with indicators (e.g. "-"), but YAML prints them as plain scalars
(no quotes), which make the YAML parser fail to parse.
For these kind of strings, we need quotes.
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: ilya-biryukov, ioeric, llvm-commits, cfe-commits
Differential Revision: https://reviews.llvm.org/D42362
Modified:
llvm/trunk/include/llvm/Support/YAMLTraits.h
llvm/trunk/unittests/Support/YAMLIOTest.cpp
Modified: llvm/trunk/include/llvm/Support/YAMLTraits.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/YAMLTraits.h?rev=323097&r1=323096&r2=323097&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/YAMLTraits.h (original)
+++ llvm/trunk/include/llvm/Support/YAMLTraits.h Mon Jan 22 02:20:48 2018
@@ -511,8 +511,6 @@ inline QuotingType needsQuotes(StringRef
return QuotingType::Single;
if (isspace(S.front()) || isspace(S.back()))
return QuotingType::Single;
- if (S.front() == ',')
- return QuotingType::Single;
if (isNull(S))
return QuotingType::Single;
if (isBool(S))
@@ -520,6 +518,13 @@ inline QuotingType needsQuotes(StringRef
if (isNumeric(S))
return QuotingType::Single;
+ // 7.3.3 Plain Style
+ // Plain scalars must not begin with most indicators, as this would cause
+ // ambiguity with other YAML constructs.
+ static constexpr char Indicators[] = R"(-?:\,[]{}#&*!|>'"%@`)";
+ if (S.find_first_of(Indicators) == 0)
+ return QuotingType::Single;
+
QuotingType MaxQuotingNeeded = QuotingType::None;
for (unsigned char C : S) {
// Alphanum is safe.
Modified: llvm/trunk/unittests/Support/YAMLIOTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/YAMLIOTest.cpp?rev=323097&r1=323096&r2=323097&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/YAMLIOTest.cpp (original)
+++ llvm/trunk/unittests/Support/YAMLIOTest.cpp Mon Jan 22 02:20:48 2018
@@ -533,6 +533,7 @@ struct StringTypes {
std::string stdstr9;
std::string stdstr10;
std::string stdstr11;
+ std::string stdstr12;
};
namespace llvm {
@@ -562,6 +563,7 @@ namespace yaml {
io.mapRequired("stdstr9", st.stdstr9);
io.mapRequired("stdstr10", st.stdstr10);
io.mapRequired("stdstr11", st.stdstr11);
+ io.mapRequired("stdstr12", st.stdstr12);
}
};
}
@@ -593,6 +595,7 @@ TEST(YAMLIO, TestReadWriteStringTypes) {
map.stdstr9 = "~";
map.stdstr10 = "0.2e20";
map.stdstr11 = "0x30";
+ map.stdstr12 = "- match";
llvm::raw_string_ostream ostr(intermediate);
Output yout(ostr);
@@ -611,6 +614,7 @@ TEST(YAMLIO, TestReadWriteStringTypes) {
EXPECT_NE(llvm::StringRef::npos, flowOut.find("'~'\n"));
EXPECT_NE(llvm::StringRef::npos, flowOut.find("'0.2e20'\n"));
EXPECT_NE(llvm::StringRef::npos, flowOut.find("'0x30'\n"));
+ EXPECT_NE(llvm::StringRef::npos, flowOut.find("'- match'\n"));
EXPECT_NE(std::string::npos, flowOut.find("'''eee"));
EXPECT_NE(std::string::npos, flowOut.find("'\"fff'"));
EXPECT_NE(std::string::npos, flowOut.find("'`ggg'"));
More information about the llvm-commits
mailing list