Forum Discussion
Powershell ignores NULL characters in string comparison?
- Apr 02, 2023
I'd suggest this isn't going to be accepted as a bug as it's related to culture. You'll find this feature (or bug) across all PowerShell versions - including Windows PowerShell from which I've produce the examples below (showing culture versus ordinal.)
Intent also matters as PowerShell is not a direct substitute for things like C# and has numerous "user friendly" interpretations going on that you just won't find in a strict language.
I'd say if you're already playing with .NET objects (as you are with DateTime), you should continue doing so by using the .Equals() method where appropriate, or perhaps even .Replace() to remove null characters if that's a concern.
The null character alone has special meaning to strings in C-like languages, so that'd be the only character you'd need to watch out for in a string equality test.
Rather than something being "fixed" in PowerShell, it would be "better" (I'm not convinced this one scenario warrants the effort but I'm speaking in hypotheticals here) to add yet another equality operator (currently, we have "eq", "ceq" and "ieq") that performs an ordinal comparison.
Cheers,
Lain
- svheldenApr 01, 2023Brass ContributorDone, thx.
https://github.com/PowerShell/PowerShell/issues/19438