llvm.org GIT mirror llvm / 802ab07
YAML: Null terminate block scalar's value. The commit null terminates the string value in the `yaml::BlockScalarNode` class. This change is motivated by the initial MIR serialization commit (r237708) that I reverted in r237730 because the LLVM IR source from the block scalar node wasn't terminated by a null character and thus the buildbots failed on one testcase sometimes. This change enables me to recommit the reverted commit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237942 91177308-0d34-0410-b5e6-96231b3b80d8 Alex Lorenz 4 years ago
2 changed file(s) with 14 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
23782378 , T.Range);
23792379 case Token::TK_BlockScalar: {
23802380 getNext();
2381 StringRef StrCopy = StringRef(T.Value).copy(NodeAllocator);
2381 StringRef NullTerminatedStr(T.Value.c_str(), T.Value.length() + 1);
2382 StringRef StrCopy = NullTerminatedStr.copy(NodeAllocator).drop_back();
23822383 return new (NodeAllocator)
23832384 BlockScalarNode(stream.CurrentDoc, AnchorInfo.Range.substr(1),
23842385 TagInfo.Range, StrCopy, T.Range);
156156 ExpectParseError("Long leading space line", "test: |\n \n Test\n");
157157 }
158158
159 TEST(YAMLParser, NullTerminatedBlockScalars) {
160 SourceMgr SM;
161 yaml::Stream Stream("test: |\n Hello\n World\n", SM);
162 yaml::Document &Doc = *Stream.begin();
163 yaml::MappingNode *Map = cast(Doc.getRoot());
164 StringRef Value =
165 cast(Map->begin()->getValue())->getValue();
166
167 EXPECT_EQ(Value, "Hello\nWorld\n");
168 EXPECT_EQ(Value.data()[Value.size()], '\0');
169 }
170
159171 TEST(YAMLParser, HandlesEndOfFileGracefully) {
160172 ExpectParseError("In string starting with EOF", "[\"");
161173 ExpectParseError("In string hitting EOF", "[\" ");