-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Incorrect behavior of string.IndexOf in different cultures #111340
Comments
From @JeroenBer on Sun, 12 Jan 2025 12:59:22 GMT In fact if the string is "", it doesn't matter what you search, it will always return 0, instead of -1 when using cultures on iOS NOTE: The other way around it should return 0 but not this way! |
From @rolfbjarne on Mon, 13 Jan 2025 09:25:58 GMT I can reproduce this with the provided sample, and it looks like a runtime issue, so moving to dotnet/runtime. |
/cc @matouskozak |
Tagging subscribers to 'os-ios': @vitek-karas, @kotlarmilos, @ivanpovazan, @steveisok, @akoeplinger |
@vitek-karas, @kotlarmilos, @ivanpovazan, @steveisok, @akoeplinger @matouskozak Can this please be fixed in the 9.0 version ? This is currently holding us back from migrating to .NET 9.0. In my opinion this is a very serious issue. It can cause all sorts of nasty problems and side effects that are very hard to discover. Also scanning/updating your own code is not enough, the bug could still appear from any external library that is being used, but that's impossible to check and hard to fix. |
Hello @JeroenBer, yes, I'm working on getting the fix merged and backported to .NET 9. The root cause was a bug in the code responsible for retrieving globalization information via Objective-C APIs and that we didn't test this code path properly. We are continuing to audit the code to find other possible issues. You can check the dotnet/runtime issues for other iOS globalization-related bugs. |
From @JeroenBer on Sun, 12 Jan 2025 12:34:19 GMT
Apple platform
iOS
Framework version
net9.0-*
Affected platform version
Dotnet version 9.0.101, ios workload 18.2.9170/9.0.100, MacBook Intel Sequoia 15.2, XCode 16.2, iPhone 15 / 16 emulator
Description
After upgrading from .NET8 to .NET9 our app crashed on Exceptions. After troubleshooting the cause is:
String.IndexOf() returns incorrect values.
The above scenario should return -1 on all cultures. On iOS it returns 0 after setting cultures. This leads to problems later since the code thinks the string is found at position 0.
On .NET8 and other platform it always returns -1. Also after setting the culture. So it seems introduced with .NET 9.
Steps to Reproduce
Did you find any workaround?
There is NO good workaround. Since it cannot be guaranteed that this behavior leeds to issues in External libraries using this trivial function.
For code in own control IndexOf stringcomparison type Ordinal can solve it.
It has something to do with the culture. Please let me know if it's reproducable ? And what the cause is ?
Are there any other culture thing going wrong on .NET 9 due to the same cause ?
I think this is a very serious bug and should be solved as soon as possible in .NET 9 iOS.
Relevant log output
No response
Copied from original issue dotnet/macios#21947
The text was updated successfully, but these errors were encountered: