From e08325202c667f26801185d9b8a788e1da91e994 Mon Sep 17 00:00:00 2001 From: Hsiao-nan Cheung Date: Mon, 13 May 2024 13:46:59 +0800 Subject: [PATCH] fix(core): Add 'PSObject.Copy()' to 'substitute()' (#5962) --- CHANGELOG.md | 2 +- lib/autoupdate.ps1 | 2 +- lib/core.ps1 | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be21251d25..2b2ec7d024 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### Bug Fixes - **scoop-search:** Catch error of parsing invalid manifest ([#5930](https://github.com/ScoopInstaller/Scoop/issues/5930)) -- **autoupdate:** Copy `PSCustomObject`-type properties within `autoupdate` to prevent reference changes ([#5934](https://github.com/ScoopInstaller/Scoop/issues/5934)) +- **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)) - **system:** Fix argument passing to `Split-PathLikeEnvVar()` in deprecated `strip_path()` ([#5937](https://github.com/ScoopInstaller/Scoop/issues/5937)) - **core:** Fix "Invoke-ExternalCommand" quoting rules ([#5945](https://github.com/ScoopInstaller/Scoop/issues/5945)) diff --git a/lib/autoupdate.ps1 b/lib/autoupdate.ps1 index 705c767451..bd24e04015 100644 --- a/lib/autoupdate.ps1 +++ b/lib/autoupdate.ps1 @@ -365,7 +365,7 @@ function Update-ManifestProperty { } } elseif ($Manifest.$currentProperty -and $Manifest.autoupdate.$currentProperty) { # Update other property (global) - $autoupdateProperty = $Manifest.autoupdate.$currentProperty.PSObject.Copy() + $autoupdateProperty = $Manifest.autoupdate.$currentProperty $newValue = substitute $autoupdateProperty $Substitutions if (($autoupdateProperty.GetType().Name -eq 'Object[]') -and ($autoupdateProperty.Length -eq 1)) { # Make sure it's an array diff --git a/lib/core.ps1 b/lib/core.ps1 index b7c3d7e128..ddd274c255 100644 --- a/lib/core.ps1 +++ b/lib/core.ps1 @@ -1225,8 +1225,8 @@ function Test-ScoopCoreOnHold() { } function substitute($entity, [Hashtable] $params, [Bool]$regexEscape = $false) { - $newentity = $entity - if ($null -ne $newentity) { + if ($null -ne $entity) { + $newentity = $entity.PSObject.Copy() switch ($entity.GetType().Name) { 'String' { $params.GetEnumerator() | ForEach-Object { @@ -1238,7 +1238,7 @@ function substitute($entity, [Hashtable] $params, [Bool]$regexEscape = $false) { } } 'Object[]' { - $newentity = $entity | ForEach-Object { ,(substitute $_ $params $regexEscape) } + $newentity = $entity | ForEach-Object { , (substitute $_ $params $regexEscape) } } 'PSCustomObject' { $newentity.PSObject.Properties | ForEach-Object { $_.Value = substitute $_.Value $params $regexEscape }