Skip to content

Commit 0f50657

Browse files
Fixed issues with escaped strings inside the phrase
We've had issues with phrases that looks like this "Byt artikel" listar artiklar direkt since the quotes will be escaped in the source. But the backslash escaping the quote should not be a part of the phrase to translate in and of itself. This is very similar to the issue with newlines we fixed here #176 I could add more cases (for instance \t) but this is the only one I know we actually use
1 parent e8192a7 commit 0f50657

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

MN.L10n.Tests/ParserTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,32 @@ public void LineBreakCharInCall()
115115

116116
Assert.Collection(result, x => Assert.Equal("Hello\nBrother", x.Phrase));
117117
}
118+
119+
[Fact]
120+
public void TestEscapedStringContainerCharacter()
121+
{
122+
var parser = new L10nParser();
123+
var result = parser.Parse(@"_s(""Hello \""friend\"". How it do?"")");
124+
125+
Assert.Collection(result, x => Assert.Equal(@"Hello ""friend"". How it do?", x.Phrase));
126+
}
127+
128+
[Fact]
129+
public void TestEscapedStringContainerCharacter2()
130+
{
131+
var parser = new L10nParser();
132+
var result = parser.Parse(@"_s('Hello \""friend\"". How it do?')");
133+
134+
Assert.Collection(result, x => Assert.Equal(@"Hello \""friend\"". How it do?", x.Phrase));
135+
}
136+
137+
[Fact]
138+
public void TestEscapedStringContainerCharacter3()
139+
{
140+
var parser = new L10nParser();
141+
var result = parser.Parse(@"_s('Hello \'friend\'. How it do?')");
142+
143+
Assert.Collection(result, x => Assert.Equal(@"Hello 'friend'. How it do?", x.Phrase));
144+
}
118145
}
119146
}

MN.L10n/L10nParser.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,17 @@ bool TryPeek(int forward)
181181
}
182182
}
183183

184-
if (inToken && !isVerbatim && source[_pos] == '\\' && TryPeek(1) && source[_pos + 1] == 'n')
184+
if (inToken && !isVerbatim && source[_pos] == '\\' && TryPeek(1) && (source[_pos + 1] == 'n' || source[_pos + 1] == _stringContainer))
185185
{
186+
if (source[_pos + 1] == 'n')
187+
{
188+
_tokenContent.Append('\n');
189+
}
190+
else if (source[_pos + 1] == _stringContainer)
191+
{
192+
_tokenContent.Append(_stringContainer);
193+
}
186194
_pos++;
187-
_tokenContent.Append('\n');
188195
}
189196
else
190197
{

0 commit comments

Comments
 (0)