From 30cb6aa376cc755efab69e3ac068fc02df11f17d Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Thu, 14 Dec 2023 22:20:12 +0300 Subject: [PATCH 1/2] Don't escape carriage return --- .../PoWriter.cs | 4 +--- .../PoWriterTests.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/OrchardCoreContrib.PoExtractor/PoWriter.cs b/src/OrchardCoreContrib.PoExtractor/PoWriter.cs index 29aa12b..1a89bda 100644 --- a/src/OrchardCoreContrib.PoExtractor/PoWriter.cs +++ b/src/OrchardCoreContrib.PoExtractor/PoWriter.cs @@ -66,7 +66,6 @@ public void WriteRecord(LocalizableString record) _writer.WriteLine($"msgstr[0] \"\""); } - _writer.WriteLine(); } @@ -82,7 +81,6 @@ public void WriteRecord(IEnumerable records) } } - /// public void Dispose() { @@ -104,7 +102,7 @@ private static string Escape(string text) var sb = new StringBuilder(text); sb.Replace("\\", "\\\\"); // \ -> \\ sb.Replace("\"", "\\\""); // " -> \" - sb.Replace("\r", "\\r"); + sb.Replace("\r\n", "\\r\\n"); sb.Replace("\n", "\\n"); return sb.ToString(); diff --git a/test/OrchardCoreContrib.PoExtractor.Tests/PoWriterTests.cs b/test/OrchardCoreContrib.PoExtractor.Tests/PoWriterTests.cs index c2cea9b..df1218b 100644 --- a/test/OrchardCoreContrib.PoExtractor.Tests/PoWriterTests.cs +++ b/test/OrchardCoreContrib.PoExtractor.Tests/PoWriterTests.cs @@ -48,6 +48,27 @@ public void WriteRecord_Escapes() Assert.Equal($"msgstr \"\"", result[1]); } + [Fact] + public void WriteRecord_ShouldNotEscape_CarriageReturn() + { + // Arrange + var localizableString = new LocalizableString + { + Text = "Orchard\rCore" + }; + + // Act + using (var writer = new PoWriter(_stream)) + { + writer.WriteRecord(localizableString); + } + + // Assert + var result = ReadPoStream(); + Assert.Equal($"msgid \"Orchard\\rCore\"", result[0]); + Assert.Equal($"msgstr \"\"", result[1]); + } + [Fact] public void WriteRecord_WritesPluralLocalizableString() { From 7314c522ac9cbad4a9a4c2d9ac1a95ab181f6b38 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Fri, 15 Dec 2023 02:26:00 +0300 Subject: [PATCH 2/2] Fix broken test --- test/OrchardCoreContrib.PoExtractor.Tests/PoWriterTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/OrchardCoreContrib.PoExtractor.Tests/PoWriterTests.cs b/test/OrchardCoreContrib.PoExtractor.Tests/PoWriterTests.cs index df1218b..a3f0c90 100644 --- a/test/OrchardCoreContrib.PoExtractor.Tests/PoWriterTests.cs +++ b/test/OrchardCoreContrib.PoExtractor.Tests/PoWriterTests.cs @@ -65,8 +65,8 @@ public void WriteRecord_ShouldNotEscape_CarriageReturn() // Assert var result = ReadPoStream(); - Assert.Equal($"msgid \"Orchard\\rCore\"", result[0]); - Assert.Equal($"msgstr \"\"", result[1]); + Assert.Equal("msgid \"Orchard\rCore\"", result[0]); + Assert.Equal("msgstr \"\"", result[1]); } [Fact]