fix: Windows PowerShell 5.1 compatibility for install.ps1#108
Merged
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
- fix Invoke-WebRequest returning byte[] instead of string in PS 5.1 - add Get-WebContent helper that decodes byte[] to string when needed - normalize CRLF in checksums content before splitting - add fallback for Get-Arch using env:PROCESSOR_ARCHITECTURE when unavailable - handle Read-Host in piped irm|iex sessions by detecting redirected input - add -SkipPathUpdate switch for non-interactive use
bbe6931 to
3e6eb92
Compare
…, and rowsFromSlice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题描述
在 Windows PowerShell 5.1 环境下执行
irm https://raw.githubusercontent.com/largeoliu/redmine-cli/master/scripts/install.ps1 | iex时,安装脚本的校验和验证功能完全失效(静默跳过),且在管道模式下Read-Host可能导致脚本挂起。根本原因
Bug 1:
Invoke-WebRequest返回byte[]而非string(核心问题)Windows PowerShell 5.1 中,
Invoke-WebRequest对text/plain类型响应的.Content属性返回System.Byte[](字节数组),而非字符串。原代码:
当
-split作用于byte[]时,PowerShell 将每个字节作为独立元素,导致正则匹配完全失败,校验和验证被静默跳过。Bug 2:
Read-Host在irm | iex管道中不可靠irm | iex管道模式下 stdin 被占用,Read-Host无法正确读取用户输入,可能导致脚本挂起或异常退出。Bug 3:
Get-Arch缺少回退方案[System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture在 .NET Framework 4.7.1 之前的版本中不可用,会导致脚本在旧版 Windows 上直接崩溃。解决方案
Get-WebContent辅助函数:检测Invoke-WebRequest返回的Content是否为byte[],若是则用[System.Text.Encoding]::UTF8.GetString()解码为字符串\r字符Get-Arch增加回退:当RuntimeInformation.OSArchitecture不可用时,使用$env:PROCESSOR_ARCHITECTURE作为回退[Console]::IsInputRedirected()检测管道模式,自动跳过Read-Host并输出手动添加 PATH 的说明-SkipPathUpdate开关:供非交互场景使用验证结果
修复前:
修复后:
安装的二进制文件
redmine.exe --version输出redmine version 0.5.0,功能正常。