Skip to content

Commit bb6a72d

Browse files
authored
FIX: Use the invariant culture for capitalization when generating code (#2156)
1 parent 3a6f538 commit bb6a72d

File tree

16 files changed

+47
-32
lines changed

16 files changed

+47
-32
lines changed

Assets/Editor/AddScenesToBuild.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using UnityEditor;
33
using UnityEditor.SceneManagement;
44
using UnityEngine;
5+
using System;
56

67
[InitializeOnLoad]
78
public class AddScenesToBuild : EditorWindow
@@ -66,7 +67,7 @@ private static bool IsPathInExcludedFolder(string path)
6667
// Check if the path or any part of it contains any of the excluded folder names
6768
foreach (string folder in excludedFolders)
6869
{
69-
if (path.ToLower().Contains(folder.ToLower()))
70+
if (path.Contains(folder, StringComparison.InvariantCultureIgnoreCase))
7071
{
7172
return true;
7273
}

Assets/Tests/InputSystem.Editor/InputActionAssetManagerTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#if UNITY_EDITOR
22

33
using System;
4+
using System.Globalization;
45
using System.IO;
6+
using System.Threading;
57
using NUnit.Framework;
68
using UnityEditor;
79
using UnityEngine;
810
using UnityEngine.InputSystem;
911
using UnityEngine.InputSystem.Editor;
12+
using UnityEngine.InputSystem.Utilities;
1013

1114
class InputActionAssetManagerEditorTests
1215
{
@@ -136,6 +139,21 @@ public void Editor_InputActionAssetManager_CanDeleteAssetOnDisk()
136139
Assert.Throws<Exception>(() => inputActionAssetManager.SaveChangesToAsset());
137140
}
138141
}
142+
143+
[Test]
144+
[Category("Editor")]
145+
[Description("A regression test for ISXB-1406")]
146+
public void Editor_InputActionAssetManager_ActionsCodeGeneration_TypeNamesAreNotAffectedByCultureChange()
147+
{
148+
var culture = Thread.CurrentThread.CurrentCulture;
149+
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfoByIetfLanguageTag("tr-TR");
150+
151+
var name = CSharpCodeHelpers.MakeTypeName("info");
152+
153+
Thread.CurrentThread.CurrentCulture = culture;
154+
155+
Assert.AreEqual('I', name[0], "Unexpected first letter in a type name.");
156+
}
139157
}
140158

141159
#endif // UNITY_EDITOR

ExternalSampleProjects/InputDeviceTester/Assets/InputDeviceTester/Scripts/Input/GamepadISX.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ protected string FirstLetterToUpper(string str)
109109
if (String.IsNullOrEmpty(str))
110110
return null;
111111
else if (str.Length == 1)
112-
return str.ToUpper();
112+
return str.ToUpperInvariant();
113113
else
114-
return char.ToUpper(str[0]) + str.Substring(1);
114+
return char.ToUpperInvariant(str[0]) + str.Substring(1);
115115
}
116116

117117
protected void ShowMessage(string msg)

ExternalSampleProjects/InputDeviceTester/Assets/InputDeviceTester/Scripts/Input/PenISX.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ private string FirstLetterToUpper(string str)
190190
if (String.IsNullOrEmpty(str))
191191
return null;
192192
else if (str.Length == 1)
193-
return str.ToUpper();
193+
return str.ToUpperInvariant();
194194
else
195-
return char.ToUpper(str[0]) + str.Substring(1);
195+
return char.ToUpperInvariant(str[0]) + str.Substring(1);
196196
}
197197

198198
private void ShowMessage(string msg)

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ however, it has to be formatted properly to pass verification tests.
1717
- Fixed the on hover behaviour of the two plus buttons in the Input Actions Editor window [ISXB-1327](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1327)
1818
- Fixed an issue on macOS which didn't detect up-left DPAD presses for Xbox controllers. [ISXB-810](https://issuetracker.unity3d.com/issues/macos-d-pad-upper-left-corner-is-not-logged-with-the-xbox-controller)
1919
- Fixed Input Actions code generation overwriting user files when the names happened to match. [ISXB-1257](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1257)
20+
- Fixed Input Actions code generation using locale-dependent rules when lowercasing and uppercasing strings. [ISXB-1406]
2021
- Fixed an issue when providing JoinPlayer with a specific split screen index. [ISXB-897](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-897)
2122
- Fixed an issue where an action with a name containing a slash "/" could not be found via `InputActionAsset.FindAction(string,bool)`. [ISXB-1306](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1306).
2223

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ public InputControlLayout ToLayout()
16731673
// Before render behavior.
16741674
if (!string.IsNullOrEmpty(beforeRender))
16751675
{
1676-
var beforeRenderLowerCase = beforeRender.ToLower();
1676+
var beforeRenderLowerCase = beforeRender.ToLowerInvariant();
16771677
if (beforeRenderLowerCase == "ignore")
16781678
layout.m_UpdateBeforeRender = false;
16791679
else if (beforeRenderLowerCase == "update")
@@ -1685,7 +1685,7 @@ public InputControlLayout ToLayout()
16851685
// CanRunInBackground flag.
16861686
if (!string.IsNullOrEmpty(runInBackground))
16871687
{
1688-
var runInBackgroundLowerCase = runInBackground.ToLower();
1688+
var runInBackgroundLowerCase = runInBackground.ToLowerInvariant();
16891689
if (runInBackgroundLowerCase == "enabled")
16901690
layout.canRunInBackground = true;
16911691
else if (runInBackgroundLowerCase == "disabled")

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,15 +559,15 @@ private static bool StringMatches(Substring str, InternedString matchTo)
559559
return true; // Wildcard at end of string so rest is matched.
560560

561561
++posInStr;
562-
nextChar = char.ToLower(str[posInStr], CultureInfo.InvariantCulture);
562+
nextChar = char.ToLowerInvariant(str[posInStr]);
563563

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

567567
if (posInMatchTo == matchToLength)
568568
return false; // Matched all the way to end of matchTo but there's more in str after the wildcard.
569569
}
570-
else if (char.ToLower(nextChar, CultureInfo.InvariantCulture) != matchToLowerCase[posInMatchTo])
570+
else if (char.ToLowerInvariant(nextChar) != matchToLowerCase[posInMatchTo])
571571
{
572572
return false;
573573
}
@@ -1156,7 +1156,7 @@ private static bool MatchPathComponent(string component, string path, ref int in
11561156
}
11571157

11581158
var charInComponent = component[indexInComponent];
1159-
if (charInComponent == nextCharInPath || char.ToLower(charInComponent, CultureInfo.InvariantCulture) == char.ToLower(nextCharInPath, CultureInfo.InvariantCulture))
1159+
if (charInComponent == nextCharInPath || char.ToLowerInvariant(charInComponent) == char.ToLowerInvariant(nextCharInPath))
11601160
{
11611161
++indexInComponent;
11621162
++indexInPath;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,18 @@ protected override void RefreshConfiguration()
7777
return;
7878
}
7979

80-
var textInfo = CultureInfo.InvariantCulture.TextInfo;
8180
// We need to lower case first because ToTitleCase preserves upper casing.
8281
// For example on Swedish Windows layout right shift display name is "HÖGER SKIFT".
8382
// Just passing it to ToTitleCase won't change anything. But passing "höger skift" will return "Höger Skift".
84-
var keyNameLowerCase = textInfo.ToLower(rawKeyName);
83+
var keyNameLowerCase = rawKeyName.ToLowerInvariant();
84+
8585
if (string.IsNullOrEmpty(keyNameLowerCase))
8686
{
8787
displayName = rawKeyName;
8888
return;
8989
}
9090

91+
var textInfo = CultureInfo.InvariantCulture.TextInfo;
9192
displayName = textInfo.ToTitleCase(keyNameLowerCase);
9293
}
9394
}

Packages/com.unity.inputsystem/InputSystem/Editor/AssetImporter/InputActionImporter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ private static void GenerateWrapperCode(AssetImportContext ctx, InputActionAsset
236236
var directory = Path.GetDirectoryName(assetPath);
237237
wrapperFilePath = Path.Combine(directory, wrapperFilePath);
238238
}
239-
else if (!wrapperFilePath.ToLower().StartsWith("assets/") &&
240-
!wrapperFilePath.ToLower().StartsWith("assets\\"))
239+
else if (!wrapperFilePath.StartsWith("assets/", StringComparison.InvariantCultureIgnoreCase) &&
240+
!wrapperFilePath.StartsWith("assets\\", StringComparison.InvariantCultureIgnoreCase))
241241
{
242242
// User-specified file in Assets/ folder.
243243
wrapperFilePath = Path.Combine("Assets", wrapperFilePath);

Packages/com.unity.inputsystem/InputSystem/Editor/InputParameterEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ public void Initialize(string label, string tooltip, string defaultName, Func<fl
210210
m_GetDefaultValue = getDefaultValue;
211211
m_ToggleLabel = EditorGUIUtility.TrTextContent("Default",
212212
defaultComesFromInputSettings
213-
? $"If enabled, the default {label.ToLower()} configured globally in the input settings is used. See Edit >> Project Settings... >> Input (NEW)."
213+
? $"If enabled, the default {label.ToLowerInvariant()} configured globally in the input settings is used. See Edit >> Project Settings... >> Input (NEW)."
214214
: "If enabled, the default value is used.");
215215
m_ValueLabel = EditorGUIUtility.TrTextContent(label, tooltip);
216216
if (defaultComesFromInputSettings)

0 commit comments

Comments
 (0)