Skip to content

Commit

Permalink
fix(core): Add 'PSObject.Copy()' to 'substitute()' (#5962)
Browse files Browse the repository at this point in the history
  • Loading branch information
niheaven committed May 13, 2024
1 parent e324fa4 commit 86d3fef
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Bug Fixes

- **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))

Expand Down
2 changes: 1 addition & 1 deletion lib/autoupdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/core.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 }
Expand Down

0 comments on commit 86d3fef

Please sign in to comment.