Title: Surrogate pairs cause misalignment in Format-Wide · Issue #23861 · PowerShell/PowerShell · GitHub
Open Graph Title: Surrogate pairs cause misalignment in Format-Wide · Issue #23861 · PowerShell/PowerShell
X Title: Surrogate pairs cause misalignment in Format-Wide · Issue #23861 · 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/23861
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Surrogate pairs cause misalignment in Format-Wide","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\n>NOTE: I'm writing this issue somewhat narrowly from the perspective of `Format-Wide`, since that's where I'm encountering it, but it likely applies elsewhere.\r\n\r\nstrings that contain surrogate pairs appear to have their length calculated as the number of `[char]`s, rather than the number of grapheme clusters (see: https://github.com/dotnet/docs/blob/main/docs/standard/base-types/character-encoding-introduction.md). This causes issues when formatting strings with tools like `Format-Wide`, which are calculating padding based on string length to put text into columns\r\n\r\n### Expected behavior\r\n\r\nI'd expect this to output aligned columns:\r\n\r\n```console\r\nPS> @(@{ \"`u{10437}\" = \"a\"},@{ \"a\" = \"a\"},@{ \"`u{10437}\" = \"a\"},\r\n@{ \"a\" = \"a\"},@{ \"`u{10437}\" = \"a\"},@{ \"a\" = \"a\"}) | fw -Column 3\r\n```\r\n\r\n\r\n\r\n### Actual behavior\r\n\r\nHowever, if a row contains a surrogate pair character, the alignment for columns in that row is off-by-one.\r\n\r\n\r\n\r\nAs a workaround, if I pad non-surrogate pair characters with a NUL character, then the columns line up like I'd expect\r\n\r\n```console\r\nPS> @(@{ \"`u{10437}\" = \"a\"},@{ \"`u{0}a\" = \"a\"},@{ \"`u{10437}\" = \"a\"},\r\n@{ \"`u{0}a\" = \"a\"},@{ \"`u{10437}\" = \"a\"},@{ \"`u{0}a\" = \"a\"}) | fw -Column 3\r\n```\r\n\r\n### Environment data\r\n\r\n```powershell\r\nPS> $PSVersionTable\r\n\r\nName Value\r\n---- -----\r\nPSVersion 7.4.2\r\nPSEdition Core\r\nGitCommitId 7.4.2\r\nOS Microsoft Windows 10.0.22635\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\r\n\r\n### Visuals\r\n\r\n\r\n","author":{"url":"https://github.com/MattKotsenas","@type":"Person","name":"MattKotsenas"},"datePublished":"2024-05-28T17:15:36Z","url":"https://github.com/PowerShell/PowerShell/issues/23861"}
| 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:4c948eb3-c76e-75fc-fac2-9edb3306cdc3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B5E2:27EE91:15F2BF:1EB3F1:6AFD6ED1 |
| html-safe-nonce | 01a633b88ac4b194061140ee0e8e712b307f53d18a615b9b4981b249b98bb1e7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNUUyOjI3RUU5MToxNUYyQkY6MUVCM0YxOjZBRkQ2RUQxIiwidmlzaXRvcl9pZCI6IjgzNjExNjgyMDMwNjUxNTkzNzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e5a66bc0b3a8456231966c1164643e114032a32222d3183d6b7265fb68d4db09 |
| hovercard-subject-tag | issue:2321563022 |
| 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/23861/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c01c2be913c02a263c75209af220d194e088b049b11354cf6ebd46ba1c94052b/PowerShell/PowerShell/issues/23861 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c01c2be913c02a263c75209af220d194e088b049b11354cf6ebd46ba1c94052b/PowerShell/PowerShell/issues/23861 |
| 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 | MattKotsenas |
| hostname | github.com |
| expected-hostname | github.com |
| None | e54006cf2b96d1ac260960edd10003132911469ccd1ec99c9803119fe2a4e032 |
| 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 | 5be0bf2b8cf26f8897d31e6bc3c232d328b12a54 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width