From f382204b46b7d81ac4c191b4bc6b73a90a730c98 Mon Sep 17 00:00:00 2001 From: yi_Xu Date: Sat, 28 May 2022 20:18:47 +0800 Subject: [PATCH 1/4] fix(core): add `Get-Encoding` function to fix missing webClient encoding (#4956) Add `Get-Encoding` function in core.ps1 closes: #4911 #4324 Co-authored-by: Hsiao-nan Cheung --- CHANGELOG.md | 3 ++- bin/checkver.ps1 | 6 +++--- bin/describe.ps1 | 3 ++- lib/autoupdate.ps1 | 16 ++++++++++------ lib/core.ps1 | 8 ++++++++ lib/description.ps1 | 3 ++- lib/manifest.ps1 | 6 ++++-- libexec/scoop-virustotal.ps1 | 3 ++- 8 files changed, 33 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e45103889f..b565892100 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,8 @@ - **chore:** Update Nonportable bucket URL ([#4955](https://github.com/ScoopInstaller/Scoop/issues/4955)) - **core:** Using `Invoke-Command` instead of `Invoke-Expression` ([#4941](https://github.com/ScoopInstaller/Scoop/issues/4941)) - **core:** Load config file before initialization ([#4932](https://github.com/ScoopInstaller/Scoop/issues/4932)) -- **core:** Allow to use '_' and '.' in bucket name ([#4952](https://github.com/ScoopInstaller/Scoop/issues/4952)) +- **core:** Allow to use '_' and '.' in bucket name ([#4952](https://github.com/ScoopInstaller/Scoop/pull/4952)) +- **core:** Add `Get-Encoding` function to fix missing webclient encoding ([#4956](https://github.com/ScoopInstaller/Scoop/pull/4956)) - **depends:** Avoid digits in archive file extension (except for .7z and .001) ([#4915](https://github.com/ScoopInstaller/Scoop/issues/4915)) - **bucket:** Don't check remote URL of non-git buckets ([#4923](https://github.com/ScoopInstaller/Scoop/issues/4923)) - **bucket:** Don't write message OK before bucket is cloned ([#4925](https://github.com/ScoopInstaller/Scoop/issues/4925)) diff --git a/bin/checkver.ps1 b/bin/checkver.ps1 index 7e089da94e..b477afc2d6 100644 --- a/bin/checkver.ps1 +++ b/bin/checkver.ps1 @@ -113,7 +113,7 @@ $Queue | ForEach-Object { } else { $wc.Headers.Add('User-Agent', (Get-UserAgent)) } - Register-ObjectEvent $wc downloadstringcompleted -ErrorAction Stop | Out-Null + Register-ObjectEvent $wc downloadDataCompleted -ErrorAction Stop | Out-Null $githubRegex = '\/releases\/tag\/(?:v|V)?([\d.]+)' @@ -190,7 +190,7 @@ $Queue | ForEach-Object { } $wc.Headers.Add('Referer', (strip_filename $url)) - $wc.DownloadStringAsync($url, $state) + $wc.DownloadDataAsync($url, $state) } function next($er) { @@ -218,7 +218,7 @@ while ($in_progress -gt 0) { $ver = $Version if (!$ver) { - $page = $ev.SourceEventArgs.Result + $page = (Get-Encoding($wc)).GetString($ev.SourceEventArgs.Result) $err = $ev.SourceEventArgs.Error if ($json.checkver.script) { $page = Invoke-Command ([scriptblock]::Create($json.checkver.script -join "`r`n")) diff --git a/bin/describe.ps1 b/bin/describe.ps1 index e2e8a81318..7d61cbc534 100644 --- a/bin/describe.ps1 +++ b/bin/describe.ps1 @@ -44,7 +44,8 @@ $Queue | ForEach-Object { try { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $home_html = $wc.DownloadString($manifest.homepage) + $data = $wc.DownloadData($manifest.homepage) + $home_html = (Get-Encoding($wc)).GetString($data) } catch { Write-Host "`n$($_.Exception.Message)" -ForegroundColor Red return diff --git a/lib/autoupdate.ps1 b/lib/autoupdate.ps1 index f6c991aa5b..7cf4f62053 100644 --- a/lib/autoupdate.ps1 +++ b/lib/autoupdate.ps1 @@ -1,12 +1,13 @@ # Must included with 'json.ps1' function find_hash_in_rdf([String] $url, [String] $basename) { - $data = $null + $xml = $null try { # Download and parse RDF XML file $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - [xml]$data = $wc.downloadstring($url) + $data = $wc.DownloadData($url) + [xml]$xml = (Get-Encoding($wc)).GetString($data) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" @@ -14,7 +15,7 @@ function find_hash_in_rdf([String] $url, [String] $basename) { } # Find file content - $digest = $data.RDF.Content | Where-Object { [String]$_.about -eq $basename } + $digest = $xml.RDF.Content | Where-Object { [String]$_.about -eq $basename } return format_hash $digest.sha256 } @@ -35,7 +36,8 @@ function find_hash_in_textfile([String] $url, [Hashtable] $substitutions, [Strin $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $hashfile = $wc.downloadstring($url) + $data = $wc.DownloadData($url) + $hashfile = (Get-Encoding($wc)).GetString($data) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" @@ -88,7 +90,8 @@ function find_hash_in_json([String] $url, [Hashtable] $substitutions, [String] $ $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $json = $wc.downloadstring($url) + $data = $wc.DownloadData($url) + $json = (Get-Encoding($wc)).GetString($data) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" @@ -108,7 +111,8 @@ function find_hash_in_xml([String] $url, [Hashtable] $substitutions, [String] $x $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $xml = [xml]$wc.downloadstring($url) + $data = $wc.DownloadData($url) + $xml = [xml]((Get-Encoding($wc)).GetString($data)) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" diff --git a/lib/core.ps1 b/lib/core.ps1 index d5917a49b3..56ca23ae9f 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -15,6 +15,14 @@ function Optimize-SecurityProtocol { } } +function Get-Encoding($wc) { + if($wc.ResponseHeaders["Content-Type"] -match 'charset=([^;]*)') { + return [System.Text.Encoding]::GetEncoding($Matches[1]) + } else { + return [System.Text.Encoding]::GetEncoding('utf-8') + } +} + function Get-UserAgent() { return "Scoop/1.0 (+http://scoop.sh/) PowerShell/$($PSVersionTable.PSVersion.Major).$($PSVersionTable.PSVersion.Minor) (Windows NT $([System.Environment]::OSVersion.Version.Major).$([System.Environment]::OSVersion.Version.Minor); $(if($env:PROCESSOR_ARCHITECTURE -eq 'AMD64'){'Win64; x64; '})$(if($env:PROCESSOR_ARCHITEW6432 -eq 'AMD64'){'WOW64; '})$PSEdition)" } diff --git a/lib/description.ps1 b/lib/description.ps1 index c6c0e2067d..ef1da13589 100644 --- a/lib/description.ps1 +++ b/lib/description.ps1 @@ -18,7 +18,8 @@ function find_description($url, $html, $redir = $false) { if($refresh -and !$redir) { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $html = $wc.downloadstring($refresh) + $data = $wc.DownloadData($refresh) + $html = (Get-Encoding($wc)).GetString($data) return find_description $refresh $html $true } diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index 3ad52483dd..e6f8056c82 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -12,7 +12,8 @@ function url_manifest($url) { try { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $str = $wc.downloadstring($url) + $data = $wc.DownloadData($url) + $str = (Get-Encoding($wc)).GetString($data) } catch [system.management.automation.methodinvocationexception] { warn "error: $($_.exception.innerexception.message)" } catch { @@ -65,7 +66,8 @@ function save_installed_manifest($app, $bucket, $dir, $url) { if ($url) { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $wc.downloadstring($url) > "$dir\manifest.json" + $data = $wc.DownloadData($url) + (Get-Encoding($wc)).GetString($data) > "$dir\manifest.json" } else { Copy-Item (manifest_path $app $bucket) "$dir\manifest.json" } diff --git a/libexec/scoop-virustotal.ps1 b/libexec/scoop-virustotal.ps1 index 5be7a10f56..cd2aa328f1 100644 --- a/libexec/scoop-virustotal.ps1 +++ b/libexec/scoop-virustotal.ps1 @@ -85,7 +85,8 @@ Function Get-VirusTotalResult($hash, $app) { $url = "https://www.virustotal.com/ui/files/$hash" $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $result = $wc.downloadstring($url) + $data = $wc.DownloadData($url) + $result = (Get-Encoding($wc)).GetString($data) $stats = json_path $result '$.data.attributes.last_analysis_stats' $malicious = json_path $stats '$.malicious' $suspicious = json_path $stats '$.suspicious' From aa3d764b088a023d83459743a563763806d7bb14 Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Fri, 10 Jun 2022 22:55:39 +0800 Subject: [PATCH 2/4] Some tweaks --- CHANGELOG.md | 4 ++-- bin/describe.ps1 | 3 +-- lib/autoupdate.ps1 | 12 ++++-------- lib/core.ps1 | 2 +- lib/description.ps1 | 3 +-- lib/manifest.ps1 | 6 ++---- libexec/scoop-virustotal.ps1 | 3 +-- 7 files changed, 12 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b565892100..e4151b5608 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,8 +10,8 @@ - **chore:** Update Nonportable bucket URL ([#4955](https://github.com/ScoopInstaller/Scoop/issues/4955)) - **core:** Using `Invoke-Command` instead of `Invoke-Expression` ([#4941](https://github.com/ScoopInstaller/Scoop/issues/4941)) - **core:** Load config file before initialization ([#4932](https://github.com/ScoopInstaller/Scoop/issues/4932)) -- **core:** Allow to use '_' and '.' in bucket name ([#4952](https://github.com/ScoopInstaller/Scoop/pull/4952)) -- **core:** Add `Get-Encoding` function to fix missing webclient encoding ([#4956](https://github.com/ScoopInstaller/Scoop/pull/4956)) +- **core:** Allow to use '_' and '.' in bucket name ([#4952](https://github.com/ScoopInstaller/Scoop/issues/4952)) +- **core:** Add `Get-Encoding` function to fix missing webclient encoding ([#4956](https://github.com/ScoopInstaller/Scoop/issues/4956)) - **depends:** Avoid digits in archive file extension (except for .7z and .001) ([#4915](https://github.com/ScoopInstaller/Scoop/issues/4915)) - **bucket:** Don't check remote URL of non-git buckets ([#4923](https://github.com/ScoopInstaller/Scoop/issues/4923)) - **bucket:** Don't write message OK before bucket is cloned ([#4925](https://github.com/ScoopInstaller/Scoop/issues/4925)) diff --git a/bin/describe.ps1 b/bin/describe.ps1 index 7d61cbc534..e92ab9d669 100644 --- a/bin/describe.ps1 +++ b/bin/describe.ps1 @@ -44,8 +44,7 @@ $Queue | ForEach-Object { try { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $data = $wc.DownloadData($manifest.homepage) - $home_html = (Get-Encoding($wc)).GetString($data) + $home_html = (Get-Encoding($wc)).GetString($wc.DownloadData($manifest.homepage)) } catch { Write-Host "`n$($_.Exception.Message)" -ForegroundColor Red return diff --git a/lib/autoupdate.ps1 b/lib/autoupdate.ps1 index 7cf4f62053..f7f715fbba 100644 --- a/lib/autoupdate.ps1 +++ b/lib/autoupdate.ps1 @@ -6,8 +6,7 @@ function find_hash_in_rdf([String] $url, [String] $basename) { $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $data = $wc.DownloadData($url) - [xml]$xml = (Get-Encoding($wc)).GetString($data) + [xml]$xml = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" @@ -36,8 +35,7 @@ function find_hash_in_textfile([String] $url, [Hashtable] $substitutions, [Strin $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $data = $wc.DownloadData($url) - $hashfile = (Get-Encoding($wc)).GetString($data) + $hashfile = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" @@ -90,8 +88,7 @@ function find_hash_in_json([String] $url, [Hashtable] $substitutions, [String] $ $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $data = $wc.DownloadData($url) - $json = (Get-Encoding($wc)).GetString($data) + $json = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" @@ -111,8 +108,7 @@ function find_hash_in_xml([String] $url, [Hashtable] $substitutions, [String] $x $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $data = $wc.DownloadData($url) - $xml = [xml]((Get-Encoding($wc)).GetString($data)) + $xml = [xml]((Get-Encoding($wc)).GetString($wc.DownloadData($url))) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" diff --git a/lib/core.ps1 b/lib/core.ps1 index 56ca23ae9f..9315f4918e 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -16,7 +16,7 @@ function Optimize-SecurityProtocol { } function Get-Encoding($wc) { - if($wc.ResponseHeaders["Content-Type"] -match 'charset=([^;]*)') { + if ($null -ne $wc.ResponseHeaders -and $wc.ResponseHeaders['Content-Type'] -match 'charset=([^;]*)') { return [System.Text.Encoding]::GetEncoding($Matches[1]) } else { return [System.Text.Encoding]::GetEncoding('utf-8') diff --git a/lib/description.ps1 b/lib/description.ps1 index ef1da13589..6f1d51bda4 100644 --- a/lib/description.ps1 +++ b/lib/description.ps1 @@ -18,8 +18,7 @@ function find_description($url, $html, $redir = $false) { if($refresh -and !$redir) { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $data = $wc.DownloadData($refresh) - $html = (Get-Encoding($wc)).GetString($data) + $html = (Get-Encoding($wc)).GetString($wc.DownloadData($refresh)) return find_description $refresh $html $true } diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index e6f8056c82..6f0633bb0f 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -12,8 +12,7 @@ function url_manifest($url) { try { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $data = $wc.DownloadData($url) - $str = (Get-Encoding($wc)).GetString($data) + $str = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) } catch [system.management.automation.methodinvocationexception] { warn "error: $($_.exception.innerexception.message)" } catch { @@ -66,8 +65,7 @@ function save_installed_manifest($app, $bucket, $dir, $url) { if ($url) { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $data = $wc.DownloadData($url) - (Get-Encoding($wc)).GetString($data) > "$dir\manifest.json" + (Get-Encoding($wc)).GetString($wc.DownloadData($url)) | Out-UTF8File "$dir\manifest.json" } else { Copy-Item (manifest_path $app $bucket) "$dir\manifest.json" } diff --git a/libexec/scoop-virustotal.ps1 b/libexec/scoop-virustotal.ps1 index cd2aa328f1..e092dbde0d 100644 --- a/libexec/scoop-virustotal.ps1 +++ b/libexec/scoop-virustotal.ps1 @@ -85,8 +85,7 @@ Function Get-VirusTotalResult($hash, $app) { $url = "https://www.virustotal.com/ui/files/$hash" $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $data = $wc.DownloadData($url) - $result = (Get-Encoding($wc)).GetString($data) + $result = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) $stats = json_path $result '$.data.attributes.last_analysis_stats' $malicious = json_path $stats '$.malicious' $suspicious = json_path $stats '$.suspicious' From e1a5f5d6cf8f009fe9d1c7ddc95ad5eac50a558a Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Fri, 10 Jun 2022 23:34:22 +0800 Subject: [PATCH 3/4] Fix changelog [skip ci] --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b207e6354a..d066fef985 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [Unreleased](https://github.com/ScoopInstaller/Scoop/compare/master...develop) + +### Features + +- **core:** Add `Get-Encoding` function to fix missing webclient encoding ([#4956](https://github.com/ScoopInstaller/Scoop/issues/4956)) + ## [v0.2.1](https://github.com/ScoopInstaller/Scoop/compare/v0.2.0...v0.2.1) - 2022-06-10 ### Features @@ -12,7 +18,6 @@ - **core:** Using `Invoke-Command` instead of `Invoke-Expression` ([#4941](https://github.com/ScoopInstaller/Scoop/issues/4941)) - **core:** Load config file before initialization ([#4932](https://github.com/ScoopInstaller/Scoop/issues/4932)) - **core:** Allow to use '_' and '.' in bucket name ([#4952](https://github.com/ScoopInstaller/Scoop/issues/4952)) -- **core:** Add `Get-Encoding` function to fix missing webclient encoding ([#4956](https://github.com/ScoopInstaller/Scoop/issues/4956)) - **depends:** Avoid digits in archive file extension (except for .7z and .001) ([#4915](https://github.com/ScoopInstaller/Scoop/issues/4915)) - **bucket:** Don't check remote URL of non-git buckets ([#4923](https://github.com/ScoopInstaller/Scoop/issues/4923)) - **bucket:** Don't write message OK before bucket is cloned ([#4925](https://github.com/ScoopInstaller/Scoop/issues/4925)) From b7291cb9bea9db601137fe935ae25c09e7c9c159 Mon Sep 17 00:00:00 2001 From: yi_Xu Date: Sat, 11 Jun 2022 10:17:15 +0800 Subject: [PATCH 4/4] fix: use respnse header for encoding --- bin/describe.ps1 | 3 ++- lib/autoupdate.ps1 | 12 ++++++++---- lib/description.ps1 | 3 ++- lib/manifest.ps1 | 6 ++++-- libexec/scoop-virustotal.ps1 | 3 ++- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/bin/describe.ps1 b/bin/describe.ps1 index e92ab9d669..ae573ba484 100644 --- a/bin/describe.ps1 +++ b/bin/describe.ps1 @@ -44,7 +44,8 @@ $Queue | ForEach-Object { try { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $home_html = (Get-Encoding($wc)).GetString($wc.DownloadData($manifest.homepage)) + $homepage = $wc.DownloadData($manifest.homepage) + $home_html = (Get-Encoding($wc)).GetString($homepage) } catch { Write-Host "`n$($_.Exception.Message)" -ForegroundColor Red return diff --git a/lib/autoupdate.ps1 b/lib/autoupdate.ps1 index f7f715fbba..7cf4f62053 100644 --- a/lib/autoupdate.ps1 +++ b/lib/autoupdate.ps1 @@ -6,7 +6,8 @@ function find_hash_in_rdf([String] $url, [String] $basename) { $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - [xml]$xml = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) + $data = $wc.DownloadData($url) + [xml]$xml = (Get-Encoding($wc)).GetString($data) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" @@ -35,7 +36,8 @@ function find_hash_in_textfile([String] $url, [Hashtable] $substitutions, [Strin $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $hashfile = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) + $data = $wc.DownloadData($url) + $hashfile = (Get-Encoding($wc)).GetString($data) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" @@ -88,7 +90,8 @@ function find_hash_in_json([String] $url, [Hashtable] $substitutions, [String] $ $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $json = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) + $data = $wc.DownloadData($url) + $json = (Get-Encoding($wc)).GetString($data) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" @@ -108,7 +111,8 @@ function find_hash_in_xml([String] $url, [Hashtable] $substitutions, [String] $x $wc = New-Object Net.Webclient $wc.Headers.Add('Referer', (strip_filename $url)) $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $xml = [xml]((Get-Encoding($wc)).GetString($wc.DownloadData($url))) + $data = $wc.DownloadData($url) + $xml = [xml]((Get-Encoding($wc)).GetString($data)) } catch [system.net.webexception] { write-host -f darkred $_ write-host -f darkred "URL $url is not valid" diff --git a/lib/description.ps1 b/lib/description.ps1 index 6f1d51bda4..ef1da13589 100644 --- a/lib/description.ps1 +++ b/lib/description.ps1 @@ -18,7 +18,8 @@ function find_description($url, $html, $redir = $false) { if($refresh -and !$redir) { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $html = (Get-Encoding($wc)).GetString($wc.DownloadData($refresh)) + $data = $wc.DownloadData($refresh) + $html = (Get-Encoding($wc)).GetString($data) return find_description $refresh $html $true } diff --git a/lib/manifest.ps1 b/lib/manifest.ps1 index d16f02da5e..27087a4c3a 100644 --- a/lib/manifest.ps1 +++ b/lib/manifest.ps1 @@ -12,7 +12,8 @@ function url_manifest($url) { try { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $str = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) + $data = $wc.DownloadData($url) + $str = (Get-Encoding($wc)).GetString($data) } catch [system.management.automation.methodinvocationexception] { warn "error: $($_.exception.innerexception.message)" } catch { @@ -66,7 +67,8 @@ function save_installed_manifest($app, $bucket, $dir, $url) { if ($url) { $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - (Get-Encoding($wc)).GetString($wc.DownloadData($url)) | Out-UTF8File "$dir\manifest.json" + $data = $wc.DownloadData($url) + (Get-Encoding($wc)).GetString($data) | Out-UTF8File "$dir\manifest.json" } else { Copy-Item (manifest_path $app $bucket) "$dir\manifest.json" } diff --git a/libexec/scoop-virustotal.ps1 b/libexec/scoop-virustotal.ps1 index e092dbde0d..cd2aa328f1 100644 --- a/libexec/scoop-virustotal.ps1 +++ b/libexec/scoop-virustotal.ps1 @@ -85,7 +85,8 @@ Function Get-VirusTotalResult($hash, $app) { $url = "https://www.virustotal.com/ui/files/$hash" $wc = New-Object Net.Webclient $wc.Headers.Add('User-Agent', (Get-UserAgent)) - $result = (Get-Encoding($wc)).GetString($wc.DownloadData($url)) + $data = $wc.DownloadData($url) + $result = (Get-Encoding($wc)).GetString($data) $stats = json_path $result '$.data.attributes.last_analysis_stats' $malicious = json_path $stats '$.malicious' $suspicious = json_path $stats '$.suspicious'