From 09c14d1c8ce88479c1127fda2c9001f95dae7e5d Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Mon, 17 Aug 2020 15:47:39 -0700 Subject: [PATCH 1/2] Remove \r\n for \n when writing to ostream --- .../CommonLib/RedirectionOutput.cpp | 13 ++++++++++++- .../IIS/test/Common.FunctionalTests/LogFileTests.cs | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RedirectionOutput.cpp b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RedirectionOutput.cpp index a3897954fa58..36ef5a2c19ce 100644 --- a/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RedirectionOutput.cpp +++ b/src/Servers/IIS/AspNetCoreModuleV2/CommonLib/RedirectionOutput.cpp @@ -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; } } diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs index 11ea36231763..5dbbc88281e6 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs @@ -53,6 +53,7 @@ private async Task CheckStdoutToFile(TestVariant variant, string path) var contents = Helpers.ReadAllTextFromFile(Helpers.GetExpectedLogName(deploymentResult, _logFolderPath), Logger); Assert.Contains("TEST MESSAGE", contents); + Assert.DoesNotContain("\r\n\r\n", contents); } // Move to separate file From 538cf9dbf0cbb54bb5699c0cd0c0907c2380fca0 Mon Sep 17 00:00:00 2001 From: Justin Kotalik Date: Mon, 17 Aug 2020 21:33:34 -0700 Subject: [PATCH 2/2] confirm test --- src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs b/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs index 5dbbc88281e6..a18346f0997f 100644 --- a/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs +++ b/src/Servers/IIS/IIS/test/Common.FunctionalTests/LogFileTests.cs @@ -54,6 +54,7 @@ private async Task CheckStdoutToFile(TestVariant variant, string path) Assert.Contains("TEST MESSAGE", contents); Assert.DoesNotContain("\r\n\r\n", contents); + Assert.Contains("\r\n", contents); } // Move to separate file