Title: Sort order difference between PowerShell 5 and PowerShell 7 · Issue #20730 · PowerShell/PowerShell · GitHub
Open Graph Title: Sort order difference between PowerShell 5 and PowerShell 7 · Issue #20730 · PowerShell/PowerShell
X Title: Sort order difference between PowerShell 5 and PowerShell 7 · Issue #20730 · PowerShell/PowerShell
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/20730
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Sort order difference between PowerShell 5 and PowerShell 7","articleBody":"### Prerequisites\r\n\r\n- [X] Write a descriptive title.\r\n- [X] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\r\n- [X] Search the existing issues.\r\n- [X] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\r\n- [X] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\r\n\r\n### Steps to reproduce\r\n\r\nI experienced a slightly different sort order when sorting a list of files (strings) by name. Upon further review, I found that, for instance, the underline (95) and the period (46) are sorted differently. \r\n\r\nIn PowerShell 5, the underline sorts before the period.\r\nIn PowerShell 7, the underline sorts after the period.\r\n\r\nThis is on the same machine, the same `get-culture`.\r\n\r\nI solved this by converting to an ArrayList and performing an Ordinal sort.\r\n`$list = New-Object System.Collections.ArrayList;$list.AddRange($mystrings )\r\n$list.Sort([System.StringComparer]::Ordinal)`\r\n\r\nIf I need to stick with Sort-Object, I convert the string to Hex strings of Unicode bytes and sort by that.\r\n`$mystrings | Sort-Object {[system.Text.Encoding]::UTF8.GetBytes($_)|ForEach-Object ToString X2}`\r\nNote that Sort-Object has a [-culture](https://learn.microsoft.com/en-us/dotnet/api/system.string?view=net-8.0#ordinal-vs-culture-sensitive-operations) option, but I couldn't find an InvariantCulture to use.\r\n\r\n\r\n### Expected behavior\r\n\r\n```console\r\n# PowerShell 5\r\n#\r\nPS> \"_\" -gt \".\"\r\nTrue\r\nPS> $mystrings = \"A\",\"B\",\"C\",\"a\",\"b\",\"c\",\"_\",\".\"\r\n$mystrings | Sort-object\r\n.\r\n_\r\nA\r\na\r\nB\r\nb\r\nC\r\nc\r\nPS> $mystrings | Sort-object | %{[int][char]$_}\r\n46\r\n95\r\n65\r\n97\r\n66\r\n98\r\n67\r\n99\r\n```\r\n\r\n\r\n### Actual behavior\r\n\r\n```console\r\n# PowerShell 7\r\n#\r\nPS> \"_\" -gt \".\"\r\nFalse\r\nPS> $mystrings = \"A\",\"B\",\"C\",\"a\",\"b\",\"c\",\"_\",\".\"\r\nPS> $mystrings | Sort-object\r\n_\r\n.\r\nA\r\na\r\nB\r\nb\r\nC\r\nc\r\nPS> $mystrings | Sort-object | %{[int][char]$_}\r\n95\r\n46\r\n65\r\n97\r\n66\r\n98\r\n67\r\n99\r\n```\r\n\r\n\r\n### Error details\r\n\r\n_No response_\r\n\r\n### Environment data\r\n\r\n```powershell\r\n$PSVersionTable\r\n\r\nName Value\r\n---- -----\r\nPSVersion 7.3.9\r\nPSEdition Core\r\nGitCommitId 7.3.9\r\nOS Microsoft Windows 10.0.22631\r\nPlatform Win32NT\r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}\r\nPSRemotingProtocolVersion 2.3\r\nSerializationVersion 1.1.0.1\r\nWSManStackVersion 3.0\r\n\r\n$PSVersionTable\r\n\r\nName Value \r\n---- ----- \r\nPSVersion 5.1.22621.2506 \r\nPSEdition Desktop \r\nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} \r\nBuildVersion 10.0.22621.2506 \r\nCLRVersion 4.0.30319.42000 \r\nWSManStackVersion 3.0 \r\nPSRemotingProtocolVersion 2.3 \r\nSerializationVersion 1.1.0.1\r\n```\r\n\r\n\r\n### Visuals\r\n\r\n_No response_","author":{"url":"https://github.com/jason-nyc","@type":"Person","name":"jason-nyc"},"datePublished":"2023-11-20T13:19:48Z","url":"https://github.com/PowerShell/PowerShell/issues/20730"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:e44fad63-892f-dc78-7d3d-1fb36d1d0cdc |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D7FE:357787:124DE2A:1934224:6AFD51CE |
| html-safe-nonce | 14e8a68f880ad5816dcd670a4489b3fc67041978a468250de44e4bdce601b1aa |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEN0ZFOjM1Nzc4NzoxMjRERTJBOjE5MzQyMjQ6NkFGRDUxQ0UiLCJ2aXNpdG9yX2lkIjoiNDYxNDMxMDk1ODIwNDgwMTQ4NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5b511c46723c02cc9d724aeecb7aa54325883512d5c89b8c7604f82ab949831e |
| hovercard-subject-tag | issue:2002195243 |
| 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/20730/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9b894c62a69d650df9206ff73ea6360fe8093df13dfab5c8991e25c8ee602831/PowerShell/PowerShell/issues/20730 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9b894c62a69d650df9206ff73ea6360fe8093df13dfab5c8991e25c8ee602831/PowerShell/PowerShell/issues/20730 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jason-nyc |
| hostname | github.com |
| expected-hostname | github.com |
| None | 66653c2e55a6fff2930be1bdf07ee4f8aa137e3956d056c822563be6f878755e |
| 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 | b6f01f7cb9f35f8c09949773241a3d49dd04b340 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width