Title: Sort-Object returns different results on default OS configs for Windows vs. Ubuntu 18.04 · Issue #8824 · PowerShell/PowerShell · GitHub
Open Graph Title: Sort-Object returns different results on default OS configs for Windows vs. Ubuntu 18.04 · Issue #8824 · PowerShell/PowerShell
X Title: Sort-Object returns different results on default OS configs for Windows vs. Ubuntu 18.04 · Issue #8824 · PowerShell/PowerShell
Description: When I use sort-object on PowerShell Core on Windows vs. Ubuntu 18.04, the results are sorted differently using the operating systems out of the box. IMO, the Windows behavior is correct, if for no other reason that it is consistent with...
Open Graph Description: When I use sort-object on PowerShell Core on Windows vs. Ubuntu 18.04, the results are sorted differently using the operating systems out of the box. IMO, the Windows behavior is correct, if for no...
X Description: When I use sort-object on PowerShell Core on Windows vs. Ubuntu 18.04, the results are sorted differently using the operating systems out of the box. IMO, the Windows behavior is correct, if for no...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/8824
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Sort-Object returns different results on default OS configs for Windows vs. Ubuntu 18.04","articleBody":"When I use sort-object on PowerShell Core on Windows vs. Ubuntu 18.04, the results are sorted differently using the operating systems out of the box. IMO, the Windows behavior is correct, if for no other reason that it is consistent with PowerShell Desktop. In general, if a language such as Javascript were to suddenly release a change that made sorting primitives native to the language behave differently on Windows vs. Linux / Mac, the web as we know it would break completely.\r\n\r\n# Steps to reproduce\r\nRun the following command on PowerShell Core 6.2.0 preview3 on Windows, and on Ubuntu 18.04:\r\n\r\n```powershell\r\n$PSVersionTable.Platform;('a', 'ab', 'aC' | Sort-Object ) -join ','\r\n```\r\n\r\n# Expected behavior\r\nThe only difference should be the Platform string, Windows vs. Linux, that is output -- the sorted object output should be the same on both platforms, like this:\r\n\r\n```powershell\r\n# The first line below is executed on Windows, the second on Ubuntu 18.04\r\nPS> $PSVersionTable.Platform;('a', 'ab', 'aC' | Sort-Object ) -join ','\r\nWin32NT\r\na,ab,aC\r\nPS> $PSVersionTable.Platform;('a', 'ab', 'aC' | Sort-Object ) -join ','\r\nUnix\r\na,ab,aC\r\n```\r\n# Actual behavior\r\nNot only are the platforms different, but Windows returns the objects in a different (correct IMO) order than on Linux!\r\n\r\n```powershell\r\n# The first line below is executed on Windows, the second on Ubuntu 18.04\r\nPS> $PSVersionTable.Platform;('a', 'ab', 'aC' | Sort-Object ) -join ','\r\nWin32NT\r\na,ab,aC\r\nPS> $PSVersionTable.Platform;('a', 'ab', 'aC' | Sort-Object ) -join ','\r\nUnix\r\na,aC,ab\r\n```\r\n# Impact\r\nThis is pretty serious -- by default, scripts running on Windows and Linux will return different results for something as canonical as sorting text strings. This breaks modules in some obvious ways for me at the moment (in my case, parameter completion is broken as it relies on sorting), but it also means there are subtle changes to fundamental assumptions of scripts that may result in seemingly non-deterministic behavior that is difficult to reproduce and apparently random. Diagnosing the root cause may also be difficult as few people would expect a built-in function like `sort-object` to exhibit this behavior.\r\n\r\nCertainly the precedent set by other dynamic languages such as Javascript, Python, or Ruby is that the behavior is consistent when using built-in language primitives to sort.\r\n\r\n# Notes\r\nPer [this comment on issue 8604](https://github.com/PowerShell/PowerShell/issues/8064#issuecomment-460127076), I tried the suggestion that configuring the LC_ALL variable on Linux would affect this, and it turns out that this is indeed the case, as demonstrated by running the following commands on `bash` on Linux:\r\n\r\n```sh\r\n# Works fine\r\nLC_ALL=en_US.UTF-8 pwsh-preview -noprofile -c \"echo \\$PSVer\r\nsionTable.PSVersion;('a', 'ab', 'aC' | Sort-Object ) -join ','\"\r\n\r\nMajor Minor Patch PreReleaseLabel BuildLabel\r\n----- ----- ----- --------------- ----------\r\n6 2 0 preview.3\r\na,ab,aC\r\n\r\n# Broken!\r\nLC_ALL=C pwsh-preview -noprofile -c \"echo \\$PSVersionTable.PSVersion;('a', 'ab', 'aC' | Sort-Object ) -join ','\"\r\n\r\nMajor Minor Patch PreReleaseLabel BuildLabel\r\n----- ----- ----- --------------- ----------\r\n6 2 0 preview.3\r\na,aC,ab\r\n```\r\n# Environment data\r\nPSVersionTable Output:\r\n\r\n```powershell\r\nPS /mnt/c/Users/adamed/src/sdk/autographps-sdk> $PSVersionTable\r\n\r\nName Value\r\n---- -----\r\nPSVersion 6.2.0-preview.3\r\nPSEdition Core\r\nGitCommitId 6.2.0-preview.3\r\nOS Linux 4.4.0-17763-Microsoft #253-Microsoft Mon Dec 31 17:49:00 PST 2018\r\nPlatform Unix\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\nIn general I would agree with [the comment on issue 8604](https://github.com/PowerShell/PowerShell/issues/8064#issuecomment-460127076) that the unix `sort` command doesn't exhibit this behavior even with `LC=C`. I would think that if the issue comes from .net core, it should be fixed there (what does `mono` do?), but if not, it seems like a fix is needed on PowerShell Core -- this is a huge portability problem and also goes against what JavaScript, Python, and Ruby have set as a standard.","author":{"url":"https://github.com/adamedx","@type":"Person","name":"adamedx"},"datePublished":"2019-02-04T15:15:02Z","url":"https://github.com/PowerShell/PowerShell/issues/8824"}
| 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:44816fd0-8dee-6779-fd27-28dd95d239ee |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D11C:391229:17F882:20B83B:6AFD4E6D |
| html-safe-nonce | 5c12d9a72ae6f8effef46b3f50b3149ca0c870e9bec1f8914255403023b68185 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTFDOjM5MTIyOToxN0Y4ODI6MjBCODNCOjZBRkQ0RTZEIiwidmlzaXRvcl9pZCI6IjE5NTMwMzM0NDY0NjQ3Njk2NDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b5e42623b5b080bfb05a351eba14757e48439747aaa8757a89d1b12fb1c32613 |
| hovercard-subject-tag | issue:406375434 |
| 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/8824/issue_layout |
| twitter:image | https://opengraph.githubassets.com/644f9ebdd74ca3c95dd3971354d9227fbe2053251641ecec6dc0c305941c66d8/PowerShell/PowerShell/issues/8824 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/644f9ebdd74ca3c95dd3971354d9227fbe2053251641ecec6dc0c305941c66d8/PowerShell/PowerShell/issues/8824 |
| og:image:alt | When I use sort-object on PowerShell Core on Windows vs. Ubuntu 18.04, the results are sorted differently using the operating systems out of the box. IMO, the Windows behavior is correct, if for no... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | adamedx |
| 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