Skip to content

fix(Get-Dependency): correct operator precedence bug when DependencyType set in PSDependOptions (#131)#173

Merged
HeyItsGilbert merged 1 commit into
masterfrom
fix/131-psdependoptions-dependencytype-operator-precedence
May 15, 2026
Merged

fix(Get-Dependency): correct operator precedence bug when DependencyType set in PSDependOptions (#131)#173
HeyItsGilbert merged 1 commit into
masterfrom
fix/131-psdependoptions-dependencytype-operator-precedence

Conversation

@HeyItsGilbert
Copy link
Copy Markdown
Member

@HeyItsGilbert HeyItsGilbert commented May 15, 2026

Summary

  • Fixes dependency override is not handled correctly when DependencyType is set to PSGalleryModule in PSDependOptions #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

  • 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).
  • Invoke-Pester .\Tests\ — 353 tests, 0 failures.
  • Confirm simple-string syntax (PsDepend = 'latest') still works without DependencyType in PSDependOptions.

🤖 Generated with Claude Code

…elseif conditions

When DependencyType was set globally via PSDependOptions, PowerShell's
-and/-or precedence caused the simple-string elseif branches to match
even for hashtable-syntax dependencies, assigning the whole hashtable
to Version instead of parsing it correctly.

Parenthesise the (-not $DependencyType -or $DependencyType -eq 'X')
sub-expression in all three branches (PSGalleryModule, GitHub, Git).

Fixes #131

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 15, 2026 23:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes operator precedence bug in Parse-Dependency where -and binding tighter than -or caused the type-check sub-expression to be incorrectly grouped. When DependencyType was set globally in PSDependOptions, hashtable dependencies were misparsed as strings. The fix adds parentheses around the (-not $DependencyType -or $DependencyType -eq '<Type>') sub-expression in all three elseif branches (PSGalleryModule, GitHub, Git).

Changes:

  • Group the DependencyType check with parentheses in the PSGalleryModule branch
  • Group the DependencyType check with parentheses in the GitHub branch
  • Group the DependencyType check with parentheses in the Git branch

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown

Test Results

    4 files  ±0     68 suites  ±0   2m 31s ⏱️ +11s
1 166 tests ±0  1 080 ✅ ±0  86 💤 ±0  0 ❌ ±0 
1 412 runs  ±0  1 324 ✅ ±0  88 💤 ±0  0 ❌ ±0 

Results for commit f8316d7. ± Comparison against base commit 73b06ec.

@HeyItsGilbert HeyItsGilbert merged commit 68a574e into master May 15, 2026
10 checks passed
@HeyItsGilbert HeyItsGilbert deleted the fix/131-psdependoptions-dependencytype-operator-precedence branch May 15, 2026 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dependency override is not handled correctly when DependencyType is set to PSGalleryModule in PSDependOptions

2 participants