Skip to content

Commit 3a456a6

Browse files
Remove \r from js template strings
This seems to be required for the string to match runtime. This is similar to how we handle verbatim strings in c#
1 parent d3d5057 commit 3a456a6

4 files changed

Lines changed: 19 additions & 3 deletions

File tree

MN.L10n.BuildTasks/MN.L10n.BuildTasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<OutputType>Exe</OutputType>
77
<StartupObject>MN.L10n.BuildTasks.Program</StartupObject>
88
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
9-
<Version>4.0.4</Version>
9+
<Version>4.0.5</Version>
1010
<Authors>Chris Gårdenberg</Authors>
1111
<Company>MultiNet Interactive AB</Company>
1212
</PropertyGroup>

MN.L10n.Tests/ParserTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,15 @@ public void TestEscapedStringContainerCharacterVerbatim()
166166
Assert.Single(result);
167167
Assert.Equal(@"Hej ""bror""\nNej", result[0].Phrase.Trim());
168168
}
169+
170+
[Fact]
171+
public void TestNewlineInJsTemplateString()
172+
{
173+
var src = "_s(`Hello\r\nbrother!`)";
174+
var parser = new L10nParser();
175+
var result = parser.Parse(src).ToList();
176+
Assert.Single(result);
177+
Assert.Equal("Hello\nbrother!", result[0].Phrase.Trim());
178+
}
169179
}
170180
}

MN.L10n/L10nParser.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,12 @@ private PhraseInvocation Unescape(PhraseInvocation phraseInvocation, bool isVerb
209209
}
210210
else
211211
{
212+
if (phraseInvocation.StringContainer == '`')
213+
{
214+
phraseInvocation.Phrase = phraseInvocation.Phrase
215+
.Replace("\r", "");
216+
}
217+
212218
for (var i = 0; i < phraseInvocation.Phrase.Length; i++)
213219
{
214220
if (phraseInvocation.Phrase[i] == '\\' && i + 1 < phraseInvocation.Phrase.Length)

MN.L10n/MN.L10n.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ Translation package</Description>
1212
<PackageProjectUrl>https://github.com/MultinetInteractive/MN.L10n</PackageProjectUrl>
1313
<RepositoryType>git</RepositoryType>
1414
<Copyright>© 20XX MultiNet Interactive AB</Copyright>
15-
<Version>4.1.3</Version>
15+
<Version>4.1.4</Version>
1616
<LangVersion>latest</LangVersion>
1717
<AutoIncrementPackageRevision>True</AutoIncrementPackageRevision>
1818
<PackageReleaseNotes>Now includes analyzer</PackageReleaseNotes>
1919
<ApplicationIcon />
2020
<OutputType>Library</OutputType>
2121
<StartupObject></StartupObject>
22-
<AssemblyVersion>4.1.3</AssemblyVersion>
22+
<AssemblyVersion>4.1.4</AssemblyVersion>
2323
</PropertyGroup>
2424

2525
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

0 commit comments

Comments
 (0)