Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Assets/Tests/InputSystem/CoreTests_Controls.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Gamepad>();
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("<Gamepad>{LeftHand}foo/*/left", "layout:Gamepad,usage:LeftHand,name:foo", "wildcard:", "name:left")]
Expand Down
3 changes: 3 additions & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -558,15 +559,15 @@ 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]);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could a fix be to convert to pass CultureInfo.InvariantCulture

E.g.
nextChar = char.ToLower(str[posInStr], CultureInfo.InvariantCulture);
or (if version allowed) :
nextChar = char.ToLowerInvariant(str[posInStr]);

and a few lines down

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToUpperInvariant is recommended here: https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings
I believe going in the other direction (lower) creates issues.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks James. I missed that comment in the Microsoft documents. I mainly suggested this as it seemed we were missing the invariantCulture altogether but agree we may need the upper case for a more complete fix.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToUpperInvariant is using Invariant Culture rules so that should be enough without needing to pass CultureInfo.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lyndon-unity @jamesmcgill I just updated whole branch to only use culture invariant char comparisons, this fixes the bug without changing to ToUpperInvariant(). I would suggest closing the ticket (as the bug is fixed) at this state and creating a new refactoring ticket for clean up the string ToLowerInvariant -> ToUpperInvariant situation. Maybe it even makes sense to do it in a bigger scale where we look at all our string storing and comparison situation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is a good step and fixes the current but. We have captured the future step in a task here:
https://jira.unity3d.com/browse/ISX-1380

nextChar = char.ToLower(str[posInStr], CultureInfo.InvariantCulture);

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

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])
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above comment

else if (char.ToLower(nextChar, CultureInfo.InvariantCulture) != matchToLowerCase[posInMatchTo])
{
return false;
}
Expand Down Expand Up @@ -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))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and again as above

if (charInComponent == nextCharInPath || char.ToLower(charInComponent, CultureInfo.InvariantCulture) == char.ToLower(nextCharInPath, CultureInfo.InvariantCulture))
{
++indexInComponent;
++indexInPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and one more as above

if (char.ToLowerInvariant(first) != char.ToLowerInvariant(second))
{
isMatch = false;
break;
Expand Down