Skip to content

Commit cdb3cbd

Browse files
authored
Remove \r\n for \n when writing to ostream (#24980)
1 parent 2ad1b6d commit cdb3cbd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RedirectionOutput.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,18 @@ void FileRedirectionOutput::Append(const std::wstring& text)
7777
{
7878
if (m_file.is_open())
7979
{
80-
const auto multiByte = to_multi_byte_string(text, CP_UTF8);
80+
auto multiByte = to_multi_byte_string(text, CP_UTF8);
81+
82+
// Writing \r\n to an ostream will cause two new lines to be written rather
83+
// than one. Change all \r\n to \n.
84+
std::string slashRslashN = "\r\n";
85+
std::string slashN = "\n";
86+
size_t start_pos = 0;
87+
while ((start_pos = multiByte.find(slashRslashN, start_pos)) != std::string::npos) {
88+
multiByte.replace(start_pos, slashRslashN.length(), slashN);
89+
start_pos += slashN.length();
90+
}
91+
8192
m_file << multiByte;
8293
}
8394
}

src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ private async Task CheckStdoutToFile(TestVariant variant, string path)
5353
var contents = Helpers.ReadAllTextFromFile(Helpers.GetExpectedLogName(deploymentResult, _logFolderPath), Logger);
5454

5555
Assert.Contains("TEST MESSAGE", contents);
56+
Assert.DoesNotContain("\r\n\r\n", contents);
57+
Assert.Contains("\r\n", contents);
5658
}
5759

5860
// Move to separate file

0 commit comments

Comments
 (0)