diff --git a/Source/utils/ini.cpp b/Source/utils/ini.cpp index 9959f55d86f..0b51363c0f1 100644 --- a/Source/utils/ini.cpp +++ b/Source/utils/ini.cpp @@ -373,30 +373,29 @@ bool OrderByValueIndex(const std::pair &a, const std::pair> entries; for (auto &[sectionName, section] : sections) { - if (!result.empty()) result += '\n'; + if (!result.empty()) result.append("\r\n"); if (!section.comment.empty()) AppendComment(section.comment, result); AppendSection(sectionName, result); entries.assign(section.entries.begin(), section.entries.end()); diff --git a/test/ini_test.cpp b/test/ini_test.cpp index 8f489a3c6a0..f35f6877026 100644 --- a/test/ini_test.cpp +++ b/test/ini_test.cpp @@ -12,6 +12,22 @@ using ::testing::ElementsAre; using ::testing::Eq; using ::testing::Field; +std::string ReplaceNewlines(std::string_view s) +{ + std::string out; + bool prevR = false; + for (const char c : s) { + if (c == '\r') { + prevR = true; + } else { + if (c == '\n' && !prevR) out += '\r'; + prevR = false; + } + out += c; + } + return out; +} + } // namespace TEST(IniTest, BasicTest) @@ -59,7 +75,7 @@ key = value const std::vector newMulti { "x", "y", "z" }; result->set("sectionA", "multi", newMulti); result->set("sectionA", "float", 10.5F); - EXPECT_EQ(result->serialize(), std::string_view(R"(; Section A comment + EXPECT_EQ(result->serialize(), ReplaceNewlines(R"(; Section A comment [sectionA] key1=newValue key2=value2