Skip to content

Commit 811e5c5

Browse files
authored
ISXB-449 fix for turkish letter i (#1664)
* FIX: updated char comparison with invariant attribute * ADD: test for different cultures * modified changelog
1 parent 8f03ce2 commit 811e5c5

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

Assets/Tests/InputSystem/CoreTests_Controls.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Globalization;
23
using System.Linq;
4+
using System.Threading;
35
using NUnit.Framework;
46
using Unity.Collections;
57
using Unity.Collections.LowLevel.Unsafe;
@@ -916,6 +918,22 @@ public void Controls_CanFindControlsByExactPathCaseInsensitive()
916918
}
917919
}
918920

921+
[Test]
922+
[Category("Controls")]
923+
public void Controls_FindControl_FindsControlDespiteTurkishCulture()
924+
{
925+
var culture = CultureInfo.CurrentCulture;
926+
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("tr-TR");
927+
928+
var gamepad = InputSystem.AddDevice<Gamepad>();
929+
using (var matches = InputSystem.FindControls("/gamePAD/LEFTSTICK"))
930+
{
931+
Assert.That(matches, Has.Count.EqualTo(1));
932+
Assert.That(matches, Has.Exactly(1).SameAs(gamepad.leftStick));
933+
}
934+
Thread.CurrentThread.CurrentCulture = culture;
935+
}
936+
919937
[Test]
920938
[Category("Controls")]
921939
[TestCase("<Gamepad>{LeftHand}foo/*/left", "layout:Gamepad,usage:LeftHand,name:foo", "wildcard:", "name:left")]

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ however, it has to be formatted properly to pass verification tests.
1818
### Changed
1919
- Changed XR Layout build behavior to create Axis2D control devices with `StickControl` type instead of `Vector2Control`.
2020

21+
### Fixed
22+
- Fixed BindingPath String-Comparison to be culture and case insensitive (case ISXB-449).
23+
2124
## [1.5.1] - 2023-03-15
2225

2326
### Fixed

Packages/com.unity.inputsystem/InputSystem/Controls/InputControlPath.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Text;
33
using System.Collections.Generic;
4+
using System.Globalization;
45
using System.Linq;
56
using Unity.Collections;
67
using UnityEngine.InputSystem.Layouts;
@@ -558,15 +559,15 @@ private static bool StringMatches(Substring str, InternedString matchTo)
558559
return true; // Wildcard at end of string so rest is matched.
559560

560561
++posInStr;
561-
nextChar = char.ToLower(str[posInStr]);
562+
nextChar = char.ToLower(str[posInStr], CultureInfo.InvariantCulture);
562563

563564
while (posInMatchTo < matchToLength && matchToLowerCase[posInMatchTo] != nextChar)
564565
++posInMatchTo;
565566

566567
if (posInMatchTo == matchToLength)
567568
return false; // Matched all the way to end of matchTo but there's more in str after the wildcard.
568569
}
569-
else if (char.ToLower(nextChar) != matchToLowerCase[posInMatchTo])
570+
else if (char.ToLower(nextChar, CultureInfo.InvariantCulture) != matchToLowerCase[posInMatchTo])
570571
{
571572
return false;
572573
}
@@ -1107,7 +1108,7 @@ private static bool MatchPathComponent(string component, string path, ref int in
11071108
}
11081109

11091110
var charInComponent = component[indexInComponent];
1110-
if (charInComponent == nextCharInPath || char.ToLower(charInComponent) == char.ToLower(nextCharInPath))
1111+
if (charInComponent == nextCharInPath || char.ToLower(charInComponent, CultureInfo.InvariantCulture) == char.ToLower(nextCharInPath, CultureInfo.InvariantCulture))
11111112
{
11121113
++indexInComponent;
11131114
++indexInPath;

Packages/com.unity.inputsystem/InputSystem/Utilities/StringHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public static bool CharacterSeparatedListsHaveAtLeastOneCommonElement(string fir
418418
var first = firstList[startIndexInFirst + i];
419419
var second = secondList[startIndexInSecond + i];
420420

421-
if (char.ToLower(first) != char.ToLower(second))
421+
if (char.ToLowerInvariant(first) != char.ToLowerInvariant(second))
422422
{
423423
isMatch = false;
424424
break;

0 commit comments

Comments
 (0)