Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ls command failed for special marks: Sort-Object and InvalidArgument errors #38

Closed
yihuajack opened this issue May 20, 2020 · 3 comments

Comments

@yihuajack
Copy link

There's no problem to run l, however, to run ls failed on PowerShell 7.0.1.
At first, there are Sort-Object errors like

Sort-Object: C:\Users\Yihua\Documents\PowerShell\Modules\Get-ChildItemColor\2.2.0\Get-ChildItemColor.psm1:60
Line |
  60 |  … ject Name | Sort-Object { LengthInBufferCells("$_") } -Descending | S …
     |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot convert value "-2171" to type "System.UInt32". Error: "Value was either too large or too small
     | for a UInt32."

The error repeats with values "-2171", "-3684", and "-3692" for many times. Then, after listing all the folders (directory), there are InvalidArgument errors like:

InvalidArgument: C:\Users\Yihua\Documents\PowerShell\Modules\Get-ChildItemColor\2.2.0\PSColorHelper.ps1:39
Line |
  39 |      [bool]$isWide = $Char -ge 0x1100 -and
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Cannot convert value "-3684" to type "System.UInt32". Error: "Value was either too large or too small
     | for a UInt32."

The error repeats with values "-3684", "-2171", "-3683", "-3692", "3688", and "-3687" for many times.

After many experiments, I found that ls command worked well for most folders but for certain situation it failed. The error information shows only before files with names that containing SBC case of quotation marks (both double and single) (“,‘), star marks (★, ※, ☆), ellipsis dots (……), dash mark (——), arrow marks (↑↓←→), tick mark (√), and shape marks (○, △, □). All other SBC and special marks work correctly. Among them, quotation marks, ellipsis dots, and dash marks are in common use.

@yihuajack
Copy link
Author

In addition, filename like 'p1.bc'$'\r' also fails

@AlessandroDiGioacchino
Copy link

AlessandroDiGioacchino commented Nov 5, 2020

I'm getting the same error with the following character: (0x2013)
This probably happens because of

[bool]$isWide = $Char -ge 0x1100 -and
    ($Char -le 0x115f -or # Hangul Jamo init. consonants
     $Char -eq 0x2329 -or $Char -eq 0x232a -or
     ([uint32]($Char - 0x2e80) -le (0xa4cf - 0x2e80) -and
      $Char -ne 0x303f) -or # CJK ... Yi
     ([uint32]($Char - 0xac00) -le (0xd7a3 - 0xac00)) -or # Hangul Syllables
     ([uint32]($Char - 0xf900) -le (0xfaff - 0xf900)) -or # CJK Compatibility Ideographs
     ([uint32]($Char - 0xfe10) -le (0xfe19 - 0xfe10)) -or # Vertical forms
     ([uint32]($Char - 0xfe30) -le (0xfe6f - 0xfe30)) -or # CJK Compatibility Forms
     ([uint32]($Char - 0xff00) -le (0xff60 - 0xff00)) -or # Fullwidth Forms
     ([uint32]($Char - 0xffe0) -le (0xffe6 - 0xffe0)))

I don't know squat about PowerShell, but I guess that this:

    ($Char -le 0x115f -or # Hangul Jamo init. consonants
     $Char -eq 0x2329 -or $Char -eq 0x232a

evaluates to false, so the next conditions are checked.
The error stems from this instruction:
[uint32]($Char - 0x2e80)
Since the result is negative, it cannot be converted to an unsigned integer.

@jpann
Copy link

jpann commented Nov 29, 2021

Seeing this as well when using Get-ChildItemColorFormatWide and the current directory contains any files or folders with with (0x2013) in their name.

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.1320
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1320
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants