From 7dffc11ab4cc72ddac1a48daad5b44413f33fb50 Mon Sep 17 00:00:00 2001 From: LinusCenterstrom Date: Wed, 6 Nov 2024 16:26:50 +0100 Subject: [PATCH] fix: Better support for phrases which contain a \n (#176) * Better support for phrases which contain a \n * Removed temporary test --- MN.L10n.BuildTasks/MN.L10n.BuildTasks.csproj | 2 +- .../MN.L10n.Javascript.Core.csproj | 2 +- .../MN.L10n.Javascript.Shared.csproj | 2 +- MN.L10n.Javascript/MN.L10n.Javascript.csproj | 4 ++-- MN.L10n.Tests/ParserTests.cs | 12 +++++++++++- MN.L10n/L10nParser.cs | 10 +++++++++- MN.L10n/MN.L10n.csproj | 4 ++-- 7 files changed, 27 insertions(+), 9 deletions(-) diff --git a/MN.L10n.BuildTasks/MN.L10n.BuildTasks.csproj b/MN.L10n.BuildTasks/MN.L10n.BuildTasks.csproj index 0a23feb..07112e9 100644 --- a/MN.L10n.BuildTasks/MN.L10n.BuildTasks.csproj +++ b/MN.L10n.BuildTasks/MN.L10n.BuildTasks.csproj @@ -6,7 +6,7 @@ Exe MN.L10n.BuildTasks.Program true - 4.0.0 + 4.0.1 Chris Gårdenberg MultiNet Interactive AB diff --git a/MN.L10n.Javascript.Core/MN.L10n.Javascript.Core.csproj b/MN.L10n.Javascript.Core/MN.L10n.Javascript.Core.csproj index af0ae51..69ffcec 100644 --- a/MN.L10n.Javascript.Core/MN.L10n.Javascript.Core.csproj +++ b/MN.L10n.Javascript.Core/MN.L10n.Javascript.Core.csproj @@ -7,7 +7,7 @@ https://github.com/MultinetInteractive/MN.L10n git © 20XX MultiNet Interactive AB - 3.0.1 + 3.0.2 diff --git a/MN.L10n.Javascript.Shared/MN.L10n.Javascript.Shared.csproj b/MN.L10n.Javascript.Shared/MN.L10n.Javascript.Shared.csproj index e8e36a1..0f8defe 100644 --- a/MN.L10n.Javascript.Shared/MN.L10n.Javascript.Shared.csproj +++ b/MN.L10n.Javascript.Shared/MN.L10n.Javascript.Shared.csproj @@ -7,7 +7,7 @@ https://github.com/MultinetInteractive/MN.L10n git © 20XX MultiNet Interactive AB - 2.0.0 + 2.0.1 True diff --git a/MN.L10n.Javascript/MN.L10n.Javascript.csproj b/MN.L10n.Javascript/MN.L10n.Javascript.csproj index 6c45550..7e6e0a1 100644 --- a/MN.L10n.Javascript/MN.L10n.Javascript.csproj +++ b/MN.L10n.Javascript/MN.L10n.Javascript.csproj @@ -3,8 +3,8 @@ net48 true - 2.0.0 - 2.0.0.0 + 2.0.1 + 2.0.0.1 diff --git a/MN.L10n.Tests/ParserTests.cs b/MN.L10n.Tests/ParserTests.cs index 653d352..9a5ef98 100644 --- a/MN.L10n.Tests/ParserTests.cs +++ b/MN.L10n.Tests/ParserTests.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.IO; +using System.Linq; using Xunit; namespace MN.L10n.Tests @@ -105,5 +106,14 @@ public void TestWorksWithLiteralTemplateStrings() var result = parser.Parse(src); Assert.Single(result); } + + [Fact] + public void LineBreakCharInCall() + { + var parser = new L10nParser(); + var result = parser.Parse("_s('Hello\\nBrother')"); + + Assert.Collection(result, x => Assert.Equal("Hello\nBrother", x.Phrase)); + } } } diff --git a/MN.L10n/L10nParser.cs b/MN.L10n/L10nParser.cs index c68dd47..d021e77 100644 --- a/MN.L10n/L10nParser.cs +++ b/MN.L10n/L10nParser.cs @@ -181,7 +181,15 @@ bool TryPeek(int forward) } } - _tokenContent.Append(source[_pos]); + if (inToken && !isVerbatim && source[_pos] == '\\' && TryPeek(1) && source[_pos + 1] == 'n') + { + _pos++; + _tokenContent.Append('\n'); + } + else + { + _tokenContent.Append(source[_pos]); + } } break; } diff --git a/MN.L10n/MN.L10n.csproj b/MN.L10n/MN.L10n.csproj index c8be3b5..ca9b0f2 100644 --- a/MN.L10n/MN.L10n.csproj +++ b/MN.L10n/MN.L10n.csproj @@ -12,13 +12,13 @@ Translation package https://github.com/MultinetInteractive/MN.L10n git © 20XX MultiNet Interactive AB - 4.0.0 + 4.0.1 True Now includes analyzer Library - 4.0.0 + 4.0.1