Skip to content
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

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

Closed
stephentoub opened this issue Nov 15, 2015 · 9 comments · Fixed by #34645
Closed
Labels
area-System.Globalization disabled-test The test is disabled in source code against the issue os-linux Linux OS (any supported distro) test-bug Problem in test source code (most likely) untriaged New issue has not been triaged by the area owner
Milestone

Comments

@stephentoub
Copy link
Member

For example, this:

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

prints out true.

ellismg referenced this issue in dotnet/corefx May 13, 2016
Baseline tests against dotnet/coreclr#2051
@AlexGhiondea
Copy link
Contributor

@tarekgh would you mind taking a look at this?

@AlexGhiondea AlexGhiondea assigned tarekgh and unassigned AlexGhiondea Feb 2, 2017
@tarekgh
Copy link
Member

tarekgh commented Feb 2, 2017

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 tarekgh assigned AlexGhiondea and unassigned tarekgh Feb 2, 2017
@AlexGhiondea AlexGhiondea removed their assignment Feb 2, 2017
@AlexGhiondea
Copy link
Contributor

Closing per @tarekgh's comments

@KristinXie1
Copy link

Disabled test, reopen it.

@KristinXie1 KristinXie1 reopened this Feb 24, 2017
@tarekgh
Copy link
Member

tarekgh commented Feb 27, 2017

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

@GrabYourPitchforks
Copy link
Member

@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.

@tarekgh
Copy link
Member

tarekgh commented Jan 29, 2020

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

@tarekgh tarekgh closed this as completed Jan 29, 2020
@msftgits msftgits transferred this issue from dotnet/coreclr Jan 30, 2020
@msftgits msftgits added this to the Future milestone Jan 30, 2020
@safern
Copy link
Member

safern commented Feb 15, 2020

There are still some tests disabled against this issue (with coreclr URL).

[ActiveIssue("https://github.com/dotnet/coreclr/issues/2051", TestPlatforms.AnyUnix)]

@ghost ghost locked as resolved and limited conversation to collaborators Jan 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Globalization disabled-test The test is disabled in source code against the issue os-linux Linux OS (any supported distro) test-bug Problem in test source code (most likely) untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants