Skip to content

Commit 68a574e

Browse files
fix(Get-Dependency): correct operator precedence bug when DependencyType set in PSDependOptions (#131) (#173)
## Summary - Fixes #131 — when `DependencyType` is set globally via `PSDependOptions`, advanced hashtable dependencies were incorrectly parsed: the entire `@{Version=...; Parameters=...}` hashtable was assigned to `Version` instead of being unpacked. - Root cause: PowerShell evaluates `-and` before `-or`, so the three `elseif` branches in `Parse-Dependency` had unintended grouping — `(-not $DependencyType) OR ($DependencyType -eq 'X')` was effectively `(... -and -not $DependencyType) OR ($DependencyType -eq 'X')`, short-circuiting to `$true` for every dependency when a type was set globally. - Fix: add parentheses around the type sub-expression in all three branches (PSGalleryModule, GitHub, Git). ## Test plan - [x] Reproduce with the issue's example: `Get-Dependency -InputObject $dep` where `PSDependOptions.DependencyType = 'PSGalleryModule'` and a dependency uses hashtable syntax — `Version` should now be `'latest'` (String), not `{Version, Parameters}` (Hashtable). - [x] `Invoke-Pester .\Tests\` — 353 tests, 0 failures. - [ ] Confirm simple-string syntax (`PsDepend = 'latest'`) still works without `DependencyType` in `PSDependOptions`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 73b06ec commit 68a574e

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

PSDepend/Public/Get-Dependency.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ function Get-Dependency {
258258
# It doesn't look like a git repo, and simple syntax: PSGalleryModule
259259
elseif( $DependencyHash -is [string] -and
260260
$Dependency -notmatch '/' -and
261-
-not $DependencyType -or
262-
$DependencyType -eq 'PSGalleryModule') {
261+
(-not $DependencyType -or
262+
$DependencyType -eq 'PSGalleryModule')) {
263263
[PSCustomObject]@{
264264
PSTypeName = 'PSDepend.Dependency'
265265
DependencyFile = $DependencyFile
@@ -284,8 +284,8 @@ function Get-Dependency {
284284
elseif($DependencyHash -is [string] -and
285285
$Dependency -match '/' -and
286286
$Dependency.split('/').count -eq 2 -and
287-
-not $DependencyType -or
288-
$DependencyType -eq 'GitHub') {
287+
(-not $DependencyType -or
288+
$DependencyType -eq 'GitHub')) {
289289
[PSCustomObject]@{
290290
PSTypeName = 'PSDepend.Dependency'
291291
DependencyFile = $DependencyFile
@@ -308,8 +308,8 @@ function Get-Dependency {
308308
# It looks like a git repo, and simple syntax: Git
309309
elseif($DependencyHash -is [string] -and
310310
$Dependency -match '/' -and
311-
-not $DependencyType -or
312-
$DependencyType -eq 'Git' ) {
311+
(-not $DependencyType -or
312+
$DependencyType -eq 'Git')) {
313313
[PSCustomObject]@{
314314
PSTypeName = 'PSDepend.Dependency'
315315
DependencyFile = $DependencyFile

0 commit comments

Comments
 (0)