Remove \r\n for \n when writing to ostream (#24980)

This commit is contained in:
Justin Kotalik 2020-08-18 09:34:43 -07:00 committed by GitHub
parent 2ad1b6d835
commit cdb3cbd620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -77,7 +77,18 @@ void FileRedirectionOutput::Append(const std::wstring& text)
{
if (m_file.is_open())
{
const auto multiByte = to_multi_byte_string(text, CP_UTF8);
auto multiByte = to_multi_byte_string(text, CP_UTF8);
// Writing \r\n to an ostream will cause two new lines to be written rather
// than one. Change all \r\n to \n.
std::string slashRslashN = "\r\n";
std::string slashN = "\n";
size_t start_pos = 0;
while ((start_pos = multiByte.find(slashRslashN, start_pos)) != std::string::npos) {
multiByte.replace(start_pos, slashRslashN.length(), slashN);
start_pos += slashN.length();
}
m_file << multiByte;
}
}

View File

@ -53,6 +53,8 @@ namespace Microsoft.AspNetCore.Server.IIS.FunctionalTests
var contents = Helpers.ReadAllTextFromFile(Helpers.GetExpectedLogName(deploymentResult, _logFolderPath), Logger);
Assert.Contains("TEST MESSAGE", contents);
Assert.DoesNotContain("\r\n\r\n", contents);
Assert.Contains("\r\n", contents);
}
// Move to separate file