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

[Bug] Can not install with url encoded in utf-8 #4911

Closed
yi-Xu-0100 opened this issue May 9, 2022 · 4 comments · Fixed by #4988
Closed

[Bug] Can not install with url encoded in utf-8 #4911

yi-Xu-0100 opened this issue May 9, 2022 · 4 comments · Fixed by #4988
Labels

Comments

@yi-Xu-0100
Copy link
Contributor

Bug Report

Current Behavior

图片

Expected Behavior

The file is encoding with utf-8, but the Webclient use default encoding, and it is not recommended.

See more in system.net.webclient.encoding and system.text.encoding.default.

Additional context/output

Possible Solution

We can solve this problem by set the Encoding for Webclient.

System details

Windows version: [e.g. 7, 8, 10]

win10

OS architecture: [e.g. 32bit, 64bit]

64bit

PowerShell version: [output of "$($PSVersionTable.PSVersion)"]

5.1.19041.1645

Additional software: [(optional) e.g. ConEmu, Git]

Scoop Configuration

default setting.

@yi-Xu-0100
Copy link
Contributor Author

@rashil2000 I get the character encoding from the Content-Type header in the response with the help of #4324 (comment).

$wc = New-Object Net.Webclient
$wc.Headers.Add('User-Agent', (Get-UserAgent))
$rawData = $wc.downloadData($url)
if($wc.ResponseHeaders["Content-Type"] -match 'charset=([^;]*)') {
  $encoding = [System.Text.Encoding]::GetEncoding($Matches[1])
} else {
  $encoding = [System.Text.Encoding]::GetEncoding('utf-8')
}
$str = $encoding.GetString($rawData)

And I found many webclient.downloadstring statements were used in different files.

May we add a function about it in files that include the utils? Or create a new file to provide this function?

@rashil2000
Copy link
Member

May we add a function about it in files that include the utils?

We can do this

@yi-Xu-0100
Copy link
Contributor Author

@rashil2000 I did not find a file that includes common utils. Or did I miss it?

@rashil2000
Copy link
Member

lib/core.ps1

yi-Xu-0100 added a commit to yi-Xu-0100/Scoop that referenced this issue May 28, 2022
Add Get-Encoding function in core.ps1

close ScoopInstaller#4911
yi-Xu-0100 added a commit to yi-Xu-0100/Scoop that referenced this issue May 28, 2022
yi-Xu-0100 added a commit to yi-Xu-0100/Scoop that referenced this issue Jun 3, 2022
yi-Xu-0100 added a commit to yi-Xu-0100/Scoop that referenced this issue Jun 9, 2022
…ing (ScoopInstaller#4956)

Add `Get-Encoding` function in core.ps1

closes: ScoopInstaller#4911 ScoopInstaller#4324

Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>
yi-Xu-0100 added a commit to yi-Xu-0100/Scoop that referenced this issue Jun 9, 2022
…ing (ScoopInstaller#4956)

Add `Get-Encoding` function in core.ps1

closes: ScoopInstaller#4911 ScoopInstaller#4324

Co-authored-by: Hsiao-nan Cheung <niheaven@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants