Title: Array.Sort method call situationally ignores string-comparer argument · Issue #14829 · PowerShell/PowerShell · GitHub
Open Graph Title: Array.Sort method call situationally ignores string-comparer argument · Issue #14829 · PowerShell/PowerShell
X Title: Array.Sort method call situationally ignores string-comparer argument · Issue #14829 · PowerShell/PowerShell
Description: Note: The problem occurs if the the array elements are invisibly [psobject]-wrapped, as happens when you create an array via a Write-Output call, for instance. As such, it is another manifestation of #5579. Array.Sort() is just one manif...
Open Graph Description: Note: The problem occurs if the the array elements are invisibly [psobject]-wrapped, as happens when you create an array via a Write-Output call, for instance. As such, it is another manifestation ...
X Description: Note: The problem occurs if the the array elements are invisibly [psobject]-wrapped, as happens when you create an array via a Write-Output call, for instance. As such, it is another manifestation ...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/14829
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Array.Sort method call situationally ignores string-comparer argument","articleBody":"Note: \r\n\r\n* The problem occurs if the the array elements are invisibly `[psobject]`-wrapped, as happens when you create an array via a `Write-Output` call, for instance.\r\n\r\n* As such, it is another manifestation of #5579.\r\n\r\n`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.\r\n\r\n## Steps to reproduce\r\n\r\n```powershell\r\n# OK, with array constructed *by an expression*.\r\n$a = \"b\", \"ä\", \"a\"; [Array]::Sort($a, [StringComparer]::Ordinal)\r\n$a -join ' ' | Should -Be \"a b ä\" # OK - non-ASCII character ä comes LAST in ordinal sorting.\r\n\r\n# !! BROKEN, with array constructed via Write-Output, resulting in\r\n# !! individually [psobject]-wrapped strings.\r\n$a = Write-Output \"b\", \"ä\", \"a\"; [Array]::Sort($a, [StringComparer]::Ordinal)\r\n$a -join ' ' | Should -Be \"a b ä\" # !! BROKEN - outputs \"a ä b\" instead\r\n```\r\n\r\n## Expected behavior\r\n\r\nBoth tests should succeed, as it shouldn't matter how the array is constructed.\r\n\r\n## Actual behavior\r\n\r\nThe 2nd test fails:\r\n\r\n```none\r\nExpected strings to be the same, but they were different. String lengths are both 5. Strings differ at index 2. \r\nExpected: 'a b ä' But was: 'a ä b'\r\n```\r\n\r\nThat is, the string-comparer argument was effectively ignored, because the `.Sort()` method saw `psobject` instances, not _strings_.\r\n\r\n## Environment data\r\n\r\n```none\r\nPowerShell Core 7.2.0-preview.3\r\n```\r\n","author":{"url":"https://github.com/mklement0","@type":"Person","name":"mklement0"},"datePublished":"2021-02-17T16:16:05.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/14829/PowerShell/issues/14829"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:de12717a-0c80-94a9-e543-20581bce2116 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EDA8:28AA31:4AAAF2:624CB0:6A5B281F |
| html-safe-nonce | 1d8ad09e19560e090eea85b3f0fb382fa0e3f7ce004b8ca3590f5104d1498075 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFREE4OjI4QUEzMTo0QUFBRjI6NjI0Q0IwOjZBNUIyODFGIiwidmlzaXRvcl9pZCI6IjYyMDIyOTE5Mzk1NTM1MTk2NDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8d7d45f57f8d820c6223e6d76091c5a4612d8b6b9aba5ae05b6a03b18ab9611d |
| hovercard-subject-tag | issue:810327519 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/14829/issue_layout |
| twitter:image | https://opengraph.githubassets.com/016871d10626f02162e89d054f3915c6e4f64a4029bc527e8e1de24ab4736dc7/PowerShell/PowerShell/issues/14829 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/016871d10626f02162e89d054f3915c6e4f64a4029bc527e8e1de24ab4736dc7/PowerShell/PowerShell/issues/14829 |
| og:image:alt | Note: The problem occurs if the the array elements are invisibly [psobject]-wrapped, as happens when you create an array via a Write-Output call, for instance. As such, it is another manifestation ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mklement0 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width