You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.net 5.0 seems to be wrong in detecting zero-terminzted string #45912
As for me, .net core 3.1 behavior looks correct and .net 5.0 does not.
Original Comments
Feedback Bot on 12/9/2020, 10:13 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
This behavior is by design. EndsWith(string) is linguistic (culture-aware), and the null character has zero weight under ICU. Caller almost certainly meant to perform an ordinal comparison via EndsWith(char) or EndsWith(..., StringComparison.Ordinal).
@GrabYourPitchforks is right. For such operation ordinal comparison has to be used. Also why need to use EndsWith at all? why not just testing str[str.Length - 1] == `\0' ?
Activity
Dotnet-GitSync-Bot commentedon Dec 10, 2020
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
danmoseley commentedon Dec 10, 2020
@safern, the repro goes away if I set
DOTNET_SYSTEM_GLOBALIZATION_USENLS=1Did we discuss this case already?
GrabYourPitchforks commentedon Dec 10, 2020
This behavior is by design.
EndsWith(string)is linguistic (culture-aware), and the null character has zero weight under ICU. Caller almost certainly meant to perform an ordinal comparison viaEndsWith(char)orEndsWith(..., StringComparison.Ordinal).safern commentedon Dec 10, 2020
Thanks, @GrabYourPitchforks you beat me to it.
tarekgh commentedon Dec 10, 2020
@GrabYourPitchforks is right. For such operation ordinal comparison has to be used. Also why need to use EndsWith at all? why not just testing
str[str.Length - 1] == `\0'?GrabYourPitchforks commentedon Dec 10, 2020
To be fair, EndsWith is more readable. And it works with empty strings. :)
tarekgh commentedon Dec 10, 2020
That is a good point. but do you consider the empty string is null terminated or not? for such user scenarios, it should be true I guess.