diff --git a/Assets/Tests/InputSystem/CoreTests_Controls.cs b/Assets/Tests/InputSystem/CoreTests_Controls.cs index ae3c25001b..be23f392a2 100644 --- a/Assets/Tests/InputSystem/CoreTests_Controls.cs +++ b/Assets/Tests/InputSystem/CoreTests_Controls.cs @@ -1,5 +1,7 @@ using System; +using System.Globalization; using System.Linq; +using System.Threading; using NUnit.Framework; using Unity.Collections; using Unity.Collections.LowLevel.Unsafe; @@ -916,6 +918,22 @@ public void Controls_CanFindControlsByExactPathCaseInsensitive() } } + [Test] + [Category("Controls")] + public void Controls_FindControl_FindsControlDespiteTurkishCulture() + { + var culture = CultureInfo.CurrentCulture; + Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("tr-TR"); + + var gamepad = InputSystem.AddDevice(); + using (var matches = InputSystem.FindControls("/gamePAD/LEFTSTICK")) + { + Assert.That(matches, Has.Count.EqualTo(1)); + Assert.That(matches, Has.Exactly(1).SameAs(gamepad.leftStick)); + } + Thread.CurrentThread.CurrentCulture = culture; + } + [Test] [Category("Controls")] [TestCase("{LeftHand}foo/*/left", "layout:Gamepad,usage:LeftHand,name:foo", "wildcard:", "name:left")] diff --git a/Packages/com.unity.inputsystem/CHANGELOG.md b/Packages/com.unity.inputsystem/CHANGELOG.md index ee214066f3..74d21998c9 100644 --- a/Packages/com.unity.inputsystem/CHANGELOG.md +++ b/Packages/com.unity.inputsystem/CHANGELOG.md @@ -18,6 +18,9 @@ however, it has to be formatted properly to pass verification tests. ### Changed - Changed XR Layout build behavior to create Axis2D control devices with `StickControl` type instead of `Vector2Control`. +### Fixed +- Fixed BindingPath String-Comparison to be culture and case insensitive (case ISXB-449). + ## [1.5.1] - 2023-03-15 ### Fixed diff --git a/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlPath.cs b/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlPath.cs index 5cbfa4a41c..c4babf93a6 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlPath.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Controls/InputControlPath.cs @@ -1,6 +1,7 @@ using System; using System.Text; using System.Collections.Generic; +using System.Globalization; using System.Linq; using Unity.Collections; using UnityEngine.InputSystem.Layouts; @@ -558,7 +559,7 @@ private static bool StringMatches(Substring str, InternedString matchTo) return true; // Wildcard at end of string so rest is matched. ++posInStr; - nextChar = char.ToLower(str[posInStr]); + nextChar = char.ToLower(str[posInStr], CultureInfo.InvariantCulture); while (posInMatchTo < matchToLength && matchToLowerCase[posInMatchTo] != nextChar) ++posInMatchTo; @@ -566,7 +567,7 @@ private static bool StringMatches(Substring str, InternedString matchTo) if (posInMatchTo == matchToLength) return false; // Matched all the way to end of matchTo but there's more in str after the wildcard. } - else if (char.ToLower(nextChar) != matchToLowerCase[posInMatchTo]) + else if (char.ToLower(nextChar, CultureInfo.InvariantCulture) != matchToLowerCase[posInMatchTo]) { return false; } @@ -1107,7 +1108,7 @@ private static bool MatchPathComponent(string component, string path, ref int in } var charInComponent = component[indexInComponent]; - if (charInComponent == nextCharInPath || char.ToLower(charInComponent) == char.ToLower(nextCharInPath)) + if (charInComponent == nextCharInPath || char.ToLower(charInComponent, CultureInfo.InvariantCulture) == char.ToLower(nextCharInPath, CultureInfo.InvariantCulture)) { ++indexInComponent; ++indexInPath; diff --git a/Packages/com.unity.inputsystem/InputSystem/Utilities/StringHelpers.cs b/Packages/com.unity.inputsystem/InputSystem/Utilities/StringHelpers.cs index 825abf52a1..19691a86bf 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Utilities/StringHelpers.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Utilities/StringHelpers.cs @@ -418,7 +418,7 @@ public static bool CharacterSeparatedListsHaveAtLeastOneCommonElement(string fir var first = firstList[startIndexInFirst + i]; var second = secondList[startIndexInSecond + i]; - if (char.ToLower(first) != char.ToLower(second)) + if (char.ToLowerInvariant(first) != char.ToLowerInvariant(second)) { isMatch = false; break;