Index: include/llvm/Support/YAMLTraits.h =================================================================== --- include/llvm/Support/YAMLTraits.h +++ include/llvm/Support/YAMLTraits.h @@ -540,12 +540,15 @@ case '.': case ',': case ' ': - // TAB (0x9), LF (0xA), CR (0xD) and NEL (0x85) are allowed. + // TAB (0x9) is allowed. case 0x9: + continue; + // LF (0xA), CR (0xD) and NEL (0x85) cause parse errors when used as values + // in 'key: value' pairs unless double-quoted. case 0xA: case 0xD: case 0x85: - continue; + return QuotingType::Double; // DEL (0x7F) are excluded from the allowed character range. case 0x7F: return QuotingType::Double; Index: unittests/Support/YAMLIOTest.cpp =================================================================== --- unittests/Support/YAMLIOTest.cpp +++ unittests/Support/YAMLIOTest.cpp @@ -249,6 +249,54 @@ EXPECT_TRUE(!!yin.error()); } +struct WithStringField { + std::string str1; + std::string str2; + std::string str3; + std::string str4; +}; + +namespace llvm { +namespace yaml { +template <> struct MappingTraits { + static void mapping(IO &io, WithStringField &fb) { + io.mapRequired("str1", fb.str1); + io.mapRequired("str2", fb.str2); + io.mapRequired("str3", fb.str3); + io.mapRequired("str4", fb.str4); + } +}; +} // namespace yaml +} // namespace llvm + +TEST(YAMLIO, MultilineStrings) { + WithStringField Original; + Original.str1 = "a multiline string\nfoobarbaz"; + Original.str2 = "another one\rfoobarbaz"; + Original.str3 = "yet another one\tfoobarbaz"; + Original.str4 = "a one-line string"; + + std::string Serialized; + { + llvm::raw_string_ostream OS(Serialized); + Output YOut(OS); + YOut << Original; + } + + WithStringField Deserialized; + { + Input YIn(Serialized); + YIn >> Deserialized; + ASSERT_FALSE(YIn.error()) + << "Parsing error occurred during deserialization. Serialized string:\n" + << Serialized; + } + EXPECT_EQ(Original.str1, Deserialized.str1); + EXPECT_EQ(Original.str2, Deserialized.str2); + EXPECT_EQ(Original.str3, Deserialized.str3); + EXPECT_EQ(Original.str4, Deserialized.str4); +} + //===----------------------------------------------------------------------===// // Test built-in types