Skip to content

Commit d337bb1

Browse files
niheavenamorphobiaCapella87
authored
chore(release): Bump to version 0.4.2 (#5964)
Co-authored-by: Xuesong <amorphobia@users.noreply.github.com> Co-authored-by: Inseo Lee <capella87@outlook.com>
2 parents d285bb0 + cddcd98 commit d337bb1

File tree

7 files changed

+79
-30
lines changed

7 files changed

+79
-30
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## [v0.4.2](https://github.com/ScoopInstaller/Scoop/compare/v0.4.1...v0.4.2) - 2024-05-14
2+
3+
### Bug Fixes
4+
5+
- **autoupdate:** Copy `PSCustomObject`-type properties within `substitute()` to prevent reference changes ([#5934](https://github.com/ScoopInstaller/Scoop/issues/5934), [#5962](https://github.com/ScoopInstaller/Scoop/issues/5962))
6+
- **core:** Fix `Invoke-ExternalCommand` quoting rules ([#5945](https://github.com/ScoopInstaller/Scoop/issues/5945))
7+
- **system:** Fix argument passing to `Split-PathLikeEnvVar()` in deprecated `strip_path()` ([#5937](https://github.com/ScoopInstaller/Scoop/issues/5937))
8+
19
## [v0.4.1](https://github.com/ScoopInstaller/Scoop/compare/v0.4.0...v0.4.1) - 2024-04-25
210

311
### Bug Fixes

lib/core.ps1

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -746,31 +746,35 @@ function Invoke-ExternalCommand {
746746
$Process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
747747
}
748748
if ($ArgumentList.Length -gt 0) {
749-
$ArgumentList = $ArgumentList | ForEach-Object { [regex]::Split($_.Replace('"', ''), '(?<=(?<![:\w])[/-]\w+) | (?=[/-])') }
750-
# Use legacy argument escaping for commands having non-standard behavior
751-
# with regard to argument passing. `msiexec` requires some args like
752-
# `TARGETDIR="C:\Program Files"`, which is non-standard, therefore we
753-
# treat it as a legacy command.
749+
# Remove existing double quotes and split arguments
750+
# '(?<=(?<![:\w])[/-]\w+) ' matches a space after a command line switch starting with a slash ('/') or a hyphen ('-')
751+
# The inner item '(?<![:\w])[/-]' matches a slash ('/') or a hyphen ('-') not preceded by a colon (':') or a word character ('\w')
752+
# so that it must be a command line switch, otherwise, it would be a path (e.g. 'C:/Program Files') or other word (e.g. 'some-arg')
753+
# ' (?=[/-])' matches a space followed by a slash ('/') or a hyphen ('-'), i.e. the space before a command line switch
754+
$ArgumentList = $ArgumentList.ForEach({ $_ -replace '"' -split '(?<=(?<![:\w])[/-]\w+) | (?=[/-])' })
755+
# Use legacy argument escaping for commands having non-standard behavior with regard to argument passing.
756+
# `msiexec` requires some args like `TARGETDIR="C:\Program Files"`, which is non-standard, therefore we treat it as a legacy command.
757+
# NSIS installer's '/D' param may not work with the ArgumentList property, so we need to escape arguments manually.
754758
# ref-1: https://learn.microsoft.com/en-us/powershell/scripting/learn/experimental-features?view=powershell-7.4#psnativecommandargumentpassing
755-
$LegacyCommand = $FilePath -match '^((cmd|cscript|find|sqlcmd|wscript|msiexec)(\.exe)?|.*\.(bat|cmd|js|vbs|wsf))$'
759+
# ref-2: https://nsis.sourceforge.io/Docs/Chapter3.html
760+
$LegacyCommand = $FilePath -match '^((cmd|cscript|find|sqlcmd|wscript|msiexec)(\.exe)?|.*\.(bat|cmd|js|vbs|wsf))$' -or
761+
($ArgumentList -match '^/S$|^/D=[A-Z]:[\\/].*$').Length -eq 2
756762
$SupportArgumentList = $Process.StartInfo.PSObject.Properties.Name -contains 'ArgumentList'
757763
if ((-not $LegacyCommand) -and $SupportArgumentList) {
758764
# ArgumentList is supported in PowerShell 6.1 and later (built on .NET Core 2.1+)
759765
# ref-1: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.argumentlist?view=net-6.0
760766
# ref-2: https://docs.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7.2#net-framework-vs-net-core
761-
$ArgumentList | ForEach-Object { $Process.StartInfo.ArgumentList.Add($_) }
767+
$ArgumentList.ForEach({ $Process.StartInfo.ArgumentList.Add($_) })
762768
} else {
763-
# escape arguments manually in lower versions, refer to https://docs.microsoft.com/en-us/previous-versions/17w5ykft(v=vs.85)
764-
$escapedArgs = $ArgumentList | ForEach-Object {
765-
# escape N consecutive backslash(es), which are followed by a double quote or at the end of the string, to 2N consecutive ones
766-
$s = $_ -replace '(\\+)(""|$)', '$1$1$2'
767-
# quote the path if it contains spaces and is not NSIS's '/D' argument
768-
# ref: https://nsis.sourceforge.io/Docs/Chapter3.html
769-
if ($s -match ' ' -and $s -notmatch '/D=[A-Z]:[\\/].*') {
770-
$s -replace '([A-Z]:[\\/].*)', '"$1"'
771-
} else {
772-
$s
773-
}
769+
# Escape arguments manually in lower versions
770+
$escapedArgs = switch -regex ($ArgumentList) {
771+
# Quote paths starting with a drive letter
772+
'(?<!/D=)[A-Z]:[\\/].*' { $_ -replace '([A-Z]:[\\/].*)', '"$1"'; continue }
773+
# Do not quote paths if it is NSIS's '/D' argument
774+
'/D=[A-Z]:[\\/].*' { $_; continue }
775+
# Quote args with spaces
776+
' ' { "`"$_`""; continue }
777+
default { $_; continue }
774778
}
775779
$Process.StartInfo.Arguments = $escapedArgs -join ' '
776780
}
@@ -1221,8 +1225,8 @@ function Test-ScoopCoreOnHold() {
12211225
}
12221226

12231227
function substitute($entity, [Hashtable] $params, [Bool]$regexEscape = $false) {
1224-
$newentity = $entity
1225-
if ($null -ne $newentity) {
1228+
if ($null -ne $entity) {
1229+
$newentity = $entity.PSObject.Copy()
12261230
switch ($entity.GetType().Name) {
12271231
'String' {
12281232
$params.GetEnumerator() | ForEach-Object {
@@ -1234,7 +1238,7 @@ function substitute($entity, [Hashtable] $params, [Bool]$regexEscape = $false) {
12341238
}
12351239
}
12361240
'Object[]' {
1237-
$newentity = $entity | ForEach-Object { ,(substitute $_ $params $regexEscape) }
1241+
$newentity = $entity | ForEach-Object { , (substitute $_ $params $regexEscape) }
12381242
}
12391243
'PSCustomObject' {
12401244
$newentity.PSObject.Properties | ForEach-Object { $_.Value = substitute $_.Value $params $regexEscape }

lib/decompress.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ function Expand-MsiArchive {
156156
$ArgList = @('x', $Path, "$DestinationPath\")
157157
} else {
158158
$MsiPath = 'msiexec.exe'
159-
$ArgList = @('/a', "`"$Path`"", '/qn', "TARGETDIR=`"$DestinationPath\SourceDir`"")
159+
$ArgList = @('/a', $Path, '/qn', "TARGETDIR=$DestinationPath\SourceDir")
160160
}
161161
$LogPath = "$(Split-Path $Path)\msi.log"
162162
if ($Switches) {

lib/system.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function env($name, $global, $val) {
162162

163163
function strip_path($orig_path, $dir) {
164164
Show-DeprecatedWarning $MyInvocation 'Split-PathLikeEnvVar'
165-
Split-PathLikeEnvVar -Name $dir -Path $orig_path
165+
Split-PathLikeEnvVar -Pattern @($dir) -Path $orig_path
166166
}
167167

168168
function add_first_in_path($dir, $global) {

test/Scoop-Decompress.Tests.ps1

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Describe 'Decompression function' -Tag 'Scoop', 'Windows', 'Decompress' {
1414

1515
function test_extract($extract_fn, $from, $removal) {
1616
$to = (strip_ext $from) -replace '\.tar$', ''
17-
& $extract_fn ($from -replace '/', '\') ($to -replace '/', '\') -Removal:$removal
17+
& $extract_fn ($from -replace '/', '\') ($to -replace '/', '\') -Removal:$removal -ExtractDir $args[0]
1818
return $to
1919
}
2020

@@ -25,7 +25,7 @@ Describe 'Decompression function' -Tag 'Scoop', 'Windows', 'Decompress' {
2525
}
2626
It 'Test cases should exist and hash should match' {
2727
$testcases | Should -Exist
28-
(Get-FileHash -Path $testcases -Algorithm SHA256).Hash.ToLower() | Should -Be '791bfce192917a2ff225dcdd87d23ae5f720b20178d85e68e4b1b56139cf8e6a'
28+
(Get-FileHash -Path $testcases -Algorithm SHA256).Hash.ToLower() | Should -Be '23a23a63e89ff95f5ef27f0cacf08055c2779cf41932266d8f509c2e200b8b63'
2929
}
3030
It 'Test cases should be extracted correctly' {
3131
{ Microsoft.PowerShell.Archive\Expand-Archive -Path $testcases -DestinationPath $working_dir } | Should -Not -Throw
@@ -50,12 +50,31 @@ Describe 'Decompression function' -Tag 'Scoop', 'Windows', 'Decompress' {
5050
$test6_1 = "$working_dir\7ZipTest6.part01.rar"
5151
$test6_2 = "$working_dir\7ZipTest6.part02.rar"
5252
$test6_3 = "$working_dir\7ZipTest6.part03.rar"
53+
$test7 = "$working_dir\NSISTest.exe"
54+
}
55+
56+
AfterEach {
57+
Remove-Item -Path $to -Recurse -Force
5358
}
5459

5560
It 'extract normal compressed file' {
5661
$to = test_extract 'Expand-7zipArchive' $test1
5762
$to | Should -Exist
5863
"$to\empty" | Should -Exist
64+
(Get-ChildItem $to).Count | Should -Be 3
65+
}
66+
67+
It 'extract "extract_dir" correctly' {
68+
$to = test_extract 'Expand-7zipArchive' $test1 $false 'tmp'
69+
$to | Should -Exist
70+
"$to\empty" | Should -Exist
71+
(Get-ChildItem $to).Count | Should -Be 1
72+
}
73+
74+
It 'extract "extract_dir" with spaces correctly' {
75+
$to = test_extract 'Expand-7zipArchive' $test1 $false 'tmp 2'
76+
$to | Should -Exist
77+
"$to\empty" | Should -Exist
5978
(Get-ChildItem $to).Count | Should -Be 1
6079
}
6180

@@ -94,21 +113,39 @@ Describe 'Decompression function' -Tag 'Scoop', 'Windows', 'Decompress' {
94113
(Get-ChildItem $to).Count | Should -Be 1
95114
}
96115

116+
It 'extract NSIS installer' {
117+
$to = test_extract 'Expand-7zipArchive' $test7
118+
$to | Should -Exist
119+
"$to\empty" | Should -Exist
120+
(Get-ChildItem $to).Count | Should -Be 1
121+
}
122+
123+
It 'self-extract NSIS installer' {
124+
$to = "$working_dir\NSIS Test"
125+
$null = Invoke-ExternalCommand -FilePath $test7 -ArgumentList @('/S', '/NCRC', "/D=$to")
126+
$to | Should -Exist
127+
"$to\empty" | Should -Exist
128+
(Get-ChildItem $to).Count | Should -Be 1
129+
}
130+
97131
It 'works with "-Removal" switch ($removal param)' {
98132
$test1 | Should -Exist
99-
test_extract 'Expand-7zipArchive' $test1 $true
133+
$to = test_extract 'Expand-7zipArchive' $test1 $true
134+
$to | Should -Exist
100135
$test1 | Should -Not -Exist
101136
$test5_1 | Should -Exist
102137
$test5_2 | Should -Exist
103138
$test5_3 | Should -Exist
104-
test_extract 'Expand-7zipArchive' $test5_1 $true
139+
$to = test_extract 'Expand-7zipArchive' $test5_1 $true
140+
$to | Should -Exist
105141
$test5_1 | Should -Not -Exist
106142
$test5_2 | Should -Not -Exist
107143
$test5_3 | Should -Not -Exist
108144
$test6_1 | Should -Exist
109145
$test6_2 | Should -Exist
110146
$test6_3 | Should -Exist
111-
test_extract 'Expand-7zipArchive' $test6_1 $true
147+
$to = test_extract 'Expand-7zipArchive' $test6_1 $true
148+
$to | Should -Exist
112149
$test6_1 | Should -Not -Exist
113150
$test6_2 | Should -Not -Exist
114151
$test6_3 | Should -Not -Exist

test/Scoop-TestLib.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# copies fixtures to a working directory
22
function setup_working($name) {
3-
$fixtures = "$PSScriptRoot/fixtures/$name"
3+
$fixtures = "$PSScriptRoot\fixtures\$name"
44
if (!(Test-Path $fixtures)) {
55
Write-Host "couldn't find fixtures for $name at $fixtures" -f red
66
exit 1
77
}
88

99
# reset working dir
10-
$working_dir = "$([IO.Path]::GetTempPath())ScoopTestFixtures/$name"
10+
$working_dir = "$([IO.Path]::GetTempPath())ScoopTestFixtures\$name"
1111

1212
if (Test-Path $working_dir) {
1313
Remove-Item -Recurse -Force $working_dir
32 KB
Binary file not shown.

0 commit comments

Comments
 (0)