Skip to content

Culture-sensitive ToLower/ToUpper breaks encoding on Turkish locales #81

Description

@skacurt

Hey,

Today was my first time using the library. While trying it out, I happened to start with the Base32 API using a simple call like this:

string encoded = Base32.Rfc4648.Encode(data);

On my machine, this immediately threw an IndexOutOfRangeException.

Then I started investigating and downgraded the package version by version and found that v5.3.0 works correctly, while newer versions do not.

Since the project's CI pipeline runs on Ubuntu, I tried reproducing the issue there. The same code worked without any problems, and the build logs confirmed that the test suite also passes successfully on Ubuntu.

Since my Windows installation uses the Turkish (tr-TR) culture, I suspected the issue might be culture-related rather than operating system-specific. To verify this, I ran the same program on Ubuntu with:

LC_ALL=tr_TR.UTF-8 dotnet test

This reproduced the exact same exception.

After debugging the source, I found the root cause. Several ToLower/ToUpper calls are culture-sensitive. Under the Turkish locale, they trigger the well-known "the Turkish I problem", which eventually leads to an IndexOutOfRangeException.

The problem is also reflected in the test suite. With the Turkish locale, the following tests fail:

  • SimpleBaseTest.Base32Test
  • SimpleBaseTest.Base36Test
  • SimpleBaseTest.MultibaseTest

I'll submit a pull request replacing the culture-sensitive case conversions with culture-invariant equivalents.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions