-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Correctness bug: String.EndsWith may ignore trailing null characters #85064
Copy link
Copy link
Closed
Description
Description
String.EndsWith can give the wrong answer for a string which ends with a null character.
Reproduction Steps
> dotnet fsi
> "\n\000".EndsWith "\n";;
val it: bool = true
> "\n\000".EndsWith '\n';;
val it: bool = false
(The problem also manifests in the invariant culture.)
Expected behavior
The string consisting of a newline should not be considered a suffix of the string consisting of a newline and then a null character.
Actual behavior
The string consisting of a newline is considered to be a suffix of the string consisting of a newline and then a null character.
Regression?
No response
Known Workarounds
Use s.EndsWith '\n' instead.
Configuration
> dotnet --version
7.0.203
Running on darwin-aarch64, obtained through Nixpkgs at commit 639d4f17218568afd6494dbd807bebb2beb9d6b3, macOS Ventura 13.3.1 (22E261).
Observed in .NET 6 on Windows x86-64 as well.
Other information
This can also be triggered with \001 or \010 instead of \000, but not \r.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Type
Fields
Give feedbackNo fields configured for issues without a type.