BUG: Turkish locale causes SWIMMER → SWİMMER and skillset data loss on save

Started by roltemurto, Today at 11:45:49 AM

Previous topic - Next topic

0 Members and 3 Guests are viewing this topic.

roltemurto

Environment:
Windows 10, Turkish locale (tr-TR)
Affects both SLXEditor 3.0.2 and NLEditor 1.42

Description:
On a system with Turkish locale, the editor corrupts .nxlv files in two ways when saving:

Skill name corruption: Skill keywords such as SWIMMER are saved as SWİMMER (with a dotted capital İ). This is caused by String.ToUpper() following Turkish locale rules, where i uppercases to İ instead of I. The NeoLemmix Player does not recognize SWİMMER as a valid keyword, so the skill is ignored entirely.
Skillset data loss: The entire $SKILLSET block is saved empty. Opening an existing level with skills defined (e.g. SWIMMER 4, DISARMER 2) and doing Save As produces a file with a blank $SKILLSET block, stripping all skill assignments. This appears to be a consequence of the same issue — the editor fails to match or write skill names when the locale-aware string comparison/conversion produces unexpected characters.

Root cause:
This is a well-known .NET pitfall sometimes called the "Turkish I problem". In most languages, i.ToUpper() produces I. However, Turkish (and a small number of other locales including Azerbaijani) have a dotted/dotless I distinction: they have four separate letters — i, İ, ı, I — and their casing rules reflect this. So on any tr-TR or az-AZ system, .NET's locale-aware string methods will silently produce different results than on any other system.
This is not a UTF-8 issue — the files are encoded correctly. It is purely a string operation behavior issue. The same bug would affect any user whose Windows system locale is set to Turkish or Azerbaijani, regardless of their keyboard layout or display language.
All calls to String.ToUpper(), String.ToLower(), and String.Compare() that deal with keywords or identifiers should explicitly pass CultureInfo.InvariantCulture to guarantee consistent behavior across all locales:

csharp
// Problematic:
keyword.ToUpper()
// Fix:
keyword.ToUpper(System.Globalization.CultureInfo.InvariantCulture)

Impact:
Any level saved through the editor loses its entire skillset. The editor is completely unusable for level creation on Turkish systems.
Affected locales are not limited to Turkish. The same dotted/dotless I distinction applies in Azerbaijani (az-AZ) and Crimean Tatar (CRT) and Kazakh (KAZ) as well.