runtime icon indicating copy to clipboard operation
runtime copied to clipboard

String.StartsWith/EndsWith/IndexOf/LastIndexOf ignoring null characters on Unix

Open stephentoub opened this issue 11 years ago • 9 comments

For example, this:

Console.WriteLine("abcte\0\0\0\0\0st".EndsWith("test"));

prints out true.

stephentoub avatar Nov 15 '15 13:11 stephentoub

@tarekgh would you mind taking a look at this?

AlexGhiondea avatar Feb 02 '17 05:02 AlexGhiondea

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.

tarekgh avatar Feb 02 '17 16:02 tarekgh

Closing per @tarekgh's comments

AlexGhiondea avatar Feb 02 '17 18:02 AlexGhiondea

Disabled test, reopen it.

KristinXie1 avatar Feb 24 '17 06:02 KristinXie1

https://github.com/dotnet/corefx/blob/master/src/System.Runtime/tests/System/StringTests.cs#L835

KristinXie1 avatar Feb 27 '17 01:02 KristinXie1

@AlexGhiondea I have marked this as a test issue and moved it to the future. please change it back if you think otherwise.

tarekgh avatar Feb 27 '17 16:02 tarekgh

@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 avatar Jan 29 '20 02:01 GrabYourPitchforks

@GrabYourPitchforks I am closing it. I assume there is no test failing because of that today.

tarekgh avatar Jan 29 '20 16:01 tarekgh

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

safern avatar Feb 15 '20 01:02 safern