FIX of PowerShell installer fails on Windows PowerShell 5.1 due to byte-array string casting.
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 19.9k
- Forks
- 2.3k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 30
Description
Issue: PowerShell installer fails on Windows PowerShell 5.1 due to byte-array string casting
The Problem
When running the install.ps1 script on Windows PowerShell 5.1 (the default shell on most Windows PCs), the installation fails with this error: error: SHA256SUMS for v0.52.0 does not list jcode-windows-x86_64.exe
Why this happens
In PowerShell 5.1, Invoke-WebRequest -UseBasicParsing returns the HTTP body as a byte array (System.Byte[]) in the .Content property when downloading raw text files (like SHA256SUMS).
When the script attempts to cast this byte array directly to a string using [string]$response.Content, PowerShell 5.1 doesn't decode the text. Instead, it converts the array into a single string of space-separated decimal values representing the raw bytes (for example, "49 98 57 51..." instead of "1b93b1c...").
Because of this, matching and parsing the text manifest fails. This issue occurs in three different places inside install.ps1:
Line 105: Resolving the latest version string.
Line 147: Splitting the download bases file.
Line 186: Verifying the SHA256 checksum manifest.
The Solution
Instead of casting the byte array directly using [string], we should decode the raw bytes using UTF-8 encoding.
To keep compatibility across both Windows PowerShell 5.1 and modern PowerShell Core (where .Content might sometimes return a decoded string directly depending on version/headers), we can check if .Content is a byte array and decode it if so:
powershell
Helper helper function to safely decode raw response content
function Get-ResponseText($response) {
if ($null -eq $response) { return "" }
if ($response.Content -is [System.Byte[]]) {
return [System.Text.Encoding]::UTF8.GetString($response.Content)
}
return [string]$response.Content
}
Or, you can simply update the three target lines to decode the byte array safely:
- Version parsing (Line 104-105)
Change from:
powershell
$metadataResponse = Invoke-WebRequest -UseBasicParsing -Uri "$ReleaseMetadataBase/latest/version"
$candidate = ([string]$metadataResponse.Content).Trim()
Change to:
powershell
$metadataResponse = Invoke-WebRequest -UseBasicParsing -Uri "$ReleaseMetadataBase/latest/version"
$content = $metadataResponse.Content
$contentText = if ($content -is [System.Byte[]]) { [System.Text.Encoding]::UTF8.GetString($content) } else { [string]$content }
$candidate = $contentText.Trim()
2. Download bases parsing (Line 146-147)
Change from:
powershell
$response = Invoke-WebRequest -UseBasicParsing -Uri "$ReleaseMetadataBase/$ReleaseTag/download-bases"
foreach ($line in ([string]$response.Content -split "r?n")) {
Change to:
powershell
$response = Invoke-WebRequest -UseBasicParsing -Uri "$ReleaseMetadataBase/$ReleaseTag/download-bases"
$content = $response.Content
$contentText = if ($content -is [System.Byte[]]) { [System.Text.Encoding]::UTF8.GetString($content) } else { [string]$content }
foreach ($line in ($contentText -split "r?n")) {
3. Checksum verification (Line 185-186)
Change from:
powershell
$response = Invoke-WebRequest -UseBasicParsing -Uri $checksumUrl
$expected = Get-JcodeSha256FromManifest -ManifestText ([string]$response.Content) -AssetName $AssetName
Change to:
powershell
$response = Invoke-WebRequest -UseBasicParsing -Uri $checksumUrl
$content = $response.Content
$contentText = if ($content -is [System.Byte[]]) { [System.Text.Encoding]::UTF8.GetString($content) } else { [string]$content }
$expected = Get-JcodeSha256FromManifest -ManifestText $contentText -AssetName $AssetName
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in install.ps1 at the three response-content sites around lines 105, 147, and 186. Run the installer under Windows PowerShell 5.1 and inspect version parsing, download-bases parsing, and checksum verification. Done means the installer decodes byte-array responses correctly and completes without the SHA256SUMS lookup error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100