String.StartsWith/EndsWith/IndexOf/LastIndexOf ignoring null characters on Unix
For example, this:
Console.WriteLine("abcte\0\0\0\0\0st".EndsWith("test"));
prints out true.
@tarekgh would you mind taking a look at this?
I believe this is by design in Linux as Linux ignore the null characters. i.e. null characters has no weights for the string comparison. if someone want to to have accurate result should use ordinal comparisons and not linguistic comparison. I understand this is different than Windows but we already have some differences between Windows and Linux in this space.
Closing per @tarekgh's comments
Disabled test, reopen it.
https://github.com/dotnet/corefx/blob/master/src/System.Runtime/tests/System/StringTests.cs#L835
@AlexGhiondea I have marked this as a test issue and moved it to the future. please change it back if you think otherwise.
@tarekgh Can this be closed? I confirmed that the null character is a weightless character in ICU.
auto status = UErrorCode{};
UCollator* collator = ucol_open("", &status);
uint8_t sortKey[64];
auto result = ucol_getSortKey(
collator,
(UChar*)L"ab\0cd",
5,
sortKey,
sizeof(sortKey));
result = ucol_getSortKey(
collator,
(UChar*)L"abcd",
4,
sortKey,
sizeof(sortKey));
The two calls above will return the same value for result and will both populate sortKey with the same data. This indicates that per ICU the strings "ab\0cd" and "abcd" are equal.
@GrabYourPitchforks I am closing it. I assume there is no test failing because of that today.
There are still some tests disabled against this issue (with coreclr URL). https://github.com/dotnet/runtime/blob/50bd5ba4ea38e293d71b6f96c3b8c10b907bdb57/src/libraries/Common/tests/Tests/System/StringTests.cs#L1682