Skip to content

Commit e0304ea

Browse files
committed
Merge branch 'main' of github.com:YarnSpinnerTool/YarnSpinner into feature/custom-line-ids
2 parents 959a631 + 6407e92 commit e0304ea

File tree

6 files changed

+74
-5
lines changed

6 files changed

+74
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1111
### Changed
1212

1313
- Fixed a bug where unbalanced markup without text siblings or children would cause an error
14+
- Fixed a bug where numbers inside markup properties were being parsed in a culture variant manner.
1415

1516
### Removed
1617

Tests/TestCases/Commands.testplan

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ command: `show 1`
2222
command: `0`
2323
command: `2 {0}`
2424
command: `regular old command`
25+
command: `zorp 2.1`
2526

2627
stop

Tests/TestCases/Commands.yarn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,6 @@ title: Start
6666
// another weird but allowed situation
6767
<<set $replacement = "ular old co">>
6868
<<reg{$replacement}mmand>>
69+
70+
<<zorp {2.1}>>
6971
===

YarnSpinner.Tests/MarkupTests.cs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,6 +1230,70 @@ public void TestMarkupMultiplePropertyParsing()
12301230

12311231
}
12321232

1233+
[Theory]
1234+
[InlineData("[p=1,1 /]")]
1235+
[InlineData("[p=-1,1 /]")]
1236+
public void TestMarkupPropertyParsingUsesInvariantNumberParsingFails(string input)
1237+
{
1238+
var targetCultures = new[] {
1239+
"en",
1240+
"zh-Hans",
1241+
"ru",
1242+
"es-US",
1243+
"es",
1244+
"sw",
1245+
"ar",
1246+
"pt-BR",
1247+
"de",
1248+
"fr",
1249+
"fr-FR",
1250+
"ja",
1251+
"pl",
1252+
"ko",
1253+
};
1254+
1255+
foreach (var culture in targetCultures)
1256+
{
1257+
System.Globalization.CultureInfo.CurrentCulture = new System.Globalization.CultureInfo(culture);
1258+
var lineParser = new LineParser();
1259+
var markup = lineParser.ParseStringWithDiagnostics(input, culture);
1260+
markup.diagnostics.Should().ContainSingle();
1261+
}
1262+
}
1263+
1264+
[Theory]
1265+
[InlineData("[p=1.1 /]", 1.1)]
1266+
[InlineData("[p=-1.1 /]",-1.1)]
1267+
public void TestMarkupPropertyParsingUsesInvariantNumber(string input, float propertyValue)
1268+
{
1269+
var targetCultures = new[] {
1270+
"en",
1271+
"zh-Hans",
1272+
"ru",
1273+
"es-US",
1274+
"es",
1275+
"sw",
1276+
"ar",
1277+
"pt-BR",
1278+
"de",
1279+
"fr",
1280+
"fr-FR",
1281+
"ja",
1282+
"pl",
1283+
"ko",
1284+
};
1285+
1286+
foreach (var culture in targetCultures)
1287+
{
1288+
System.Globalization.CultureInfo.CurrentCulture = new System.Globalization.CultureInfo(culture);
1289+
var lineParser = new LineParser();
1290+
var markup = lineParser.ParseStringWithDiagnostics(input, culture);
1291+
markup.diagnostics.Should().BeEmpty();
1292+
markup.markup.Attributes[0].Properties["p"].FloatValue.Should().Be(propertyValue);
1293+
}
1294+
}
1295+
1296+
12331297
[Theory]
12341298
[InlineData(@"[a p=""string""]s[/a]", MarkupValueType.String, "string")]
12351299
[InlineData(@"[a p=""str\""ing""]s[/a]", MarkupValueType.String, @"str""ing")]
@@ -1253,6 +1317,8 @@ public void TestMarkupPropertyParsing(string input, MarkupValueType expectedType
12531317
var lineParser = new LineParser();
12541318
var markup = lineParser.ParseString(input, "en");
12551319

1320+
markup.Attributes.Should().ContainSingle();
1321+
12561322
var attribute = markup.Attributes[0];
12571323
var propertyValue = attribute.Properties["p"];
12581324

YarnSpinner/VirtualMachine.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,6 @@ internal void RunInstruction(Instruction i)
567567
// passes it to the client as a line
568568
string stringKey = i.RunLine.LineID;
569569

570-
571570
var expressionCount = i.RunLine.SubstitutionCount;
572571

573572
var strings = new string[expressionCount];

YarnSpinner/YarnSpinner.Markup/LineParser.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,8 @@ internal List<LexerToken> LexMarkup(string input)
517517
// now here we have gobbled every contiguous digit/period
518518
// so can finish up the token and return to tag mode
519519
// but before we do that we want to do a quick check to see if its actually a valid float
520-
521520
#pragma warning disable CA1846 // Prefer 'AsSpan' over 'Substring' (not available in .NET Standard 2.0)
522-
if (float.TryParse(input.Substring(token.Start, currentPosition + 1 - token.Start), out _))
521+
if (float.TryParse(input.Substring(token.Start, currentPosition + 1 - token.Start), System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out _))
523522
#pragma warning restore CA1846 // Prefer 'AsSpan' over 'Substring'
524523
{
525524
token.End = currentPosition;
@@ -960,7 +959,8 @@ bool TryIntFromToken(LexerToken token, out int value)
960959
{
961960
var valueString = OG.Substring(token.Start, token.Range);
962961

963-
if (int.TryParse(valueString, out value))
962+
963+
if (int.TryParse(valueString, System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out value))
964964
{
965965
return true;
966966
}
@@ -972,7 +972,7 @@ bool TryFloatFromToken(LexerToken token, out float value)
972972
{
973973
var valueString = OG.Substring(token.Start, token.Range);
974974

975-
if (float.TryParse(valueString, out value))
975+
if (float.TryParse(valueString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out value))
976976
{
977977
return true;
978978
}

0 commit comments

Comments
 (0)