Skip to content

Commit c8440a3

Browse files
HeyItsGilbertclaude
andcommitted
fix: InputObject hashtable no longer mutated by Get-Dependency (#35)
Parse-Dependency called $Dependencies.Remove('PSDependOptions') on the original hashtable because $Dependencies was assigned by reference. Clone each element before Parse-Dependency runs so the caller's object is left intact and a second Invoke-PSDepend / Get-Dependency call still honours PSDependOptions (e.g. Target). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ddff015 commit c8440a3

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- `Get-Dependency -InputObject` no longer mutates the caller's hashtable:
13+
`PSDependOptions` is now preserved after the call, so a second invocation
14+
with the same object still honors global options such as `Target` (#35).
15+
1016
## [0.4.1] - 2026-06-12
1117

1218
### Added

PSDepend/Public/Get-Dependency.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@
437437
elseif ($PSCmdlet.ParameterSetName -eq 'Hashtable') {
438438
$DependencyFile = 'Hashtable'
439439
$ParsedDependencies = foreach ($InputDependency in $InputObject) {
440-
$Dependencies = $InputDependency
440+
$Dependencies = $InputDependency.Clone()
441441

442442
Parse-Dependency -ParamSet $PSCmdlet.ParameterSetName
443443
}

Tests/PSDepend.Tests.ps1

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,26 @@ Describe "Get-Dependency PS$PSVersion" -Tag 'Unit' {
119119
$Dependencies | Should -BeNullOrEmpty
120120
}
121121

122+
It 'Does not mutate the caller''s InputObject — PSDependOptions key survives after Get-Dependency' {
123+
$inputObj = @{
124+
PSDependOptions = @{ Target = 'CurrentUser' }
125+
Pester = 'latest'
126+
}
127+
$null = Get-Dependency -InputObject $inputObj
128+
$inputObj.ContainsKey('PSDependOptions') | Should -Be $True
129+
}
130+
131+
It 'Does not mutate the caller''s InputObject — PSDependOptions honored on a second Get-Dependency call' {
132+
$inputObj = @{
133+
PSDependOptions = @{ Target = 'CurrentUser' }
134+
Pester = 'latest'
135+
}
136+
$null = Get-Dependency -InputObject $inputObj
137+
$null = Get-Dependency -InputObject $inputObj
138+
$inputObj.ContainsKey('PSDependOptions') | Should -Be $True
139+
$inputObj.PSDependOptions.Target | Should -Be 'CurrentUser'
140+
}
141+
122142
It 'Parses -InputObject hashtable as PSGalleryModule by default' {
123143
$Dependencies = Get-Dependency -InputObject @{ Pester = 'latest' }
124144
$Dependencies.DependencyName | Should -Be 'Pester'

0 commit comments

Comments
 (0)