Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Array.Sort method call situationally ignores string-comparer argument #14829

Copy link
Copy link
@mklement0

Description

@mklement0
Issue body actions

Note:

Array.Sort() is just one manifestation: any .NET method call with an array / object[]-typed array argument that relies on seeing the true array element types rather than their incidental [psobject] wrappers will behave unexpectedly from the user's perspective.

Steps to reproduce

# OK, with array constructed *by an expression*.
$a = "b", "ä", "a"; [Array]::Sort($a, [StringComparer]::Ordinal)
$a -join ' ' | Should -Be "a b ä"  # OK - non-ASCII character ä comes LAST in ordinal sorting.

# !! BROKEN, with array constructed via Write-Output, resulting in
# !! individually [psobject]-wrapped strings.
$a = Write-Output "b", "ä", "a"; [Array]::Sort($a, [StringComparer]::Ordinal)
$a -join ' ' | Should -Be "a b ä"  # !! BROKEN - outputs "a ä b" instead

Expected behavior

Both tests should succeed, as it shouldn't matter how the array is constructed.

Actual behavior

The 2nd test fails:

Expected strings to be the same, but they were different. String lengths are both 5. Strings differ at index 2. 
Expected: 'a b ä' But was:  'a ä b'

That is, the string-comparer argument was effectively ignored, because the .Sort() method saw psobject instances, not strings.

Environment data

PowerShell Core 7.2.0-preview.3
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-InvestigationThe behavior reported in the issue is unexpected and needs further investigation.The behavior reported in the issue is unexpected and needs further investigation.Resolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Engine-ETS

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.