fix(Get-Dependency): correct operator precedence bug when DependencyType set in PSDependOptions (#131)#173
Merged
HeyItsGilbert merged 1 commit intoMay 15, 2026
Conversation
…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>
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DependencyTypeis set globally viaPSDependOptions, advanced hashtable dependencies were incorrectly parsed: the entire@{Version=...; Parameters=...}hashtable was assigned toVersioninstead of being unpacked.-andbefore-or, so the threeelseifbranches inParse-Dependencyhad unintended grouping —(-not $DependencyType) OR ($DependencyType -eq 'X')was effectively(... -and -not $DependencyType) OR ($DependencyType -eq 'X'), short-circuiting to$truefor every dependency when a type was set globally.Test plan
Get-Dependency -InputObject $depwherePSDependOptions.DependencyType = 'PSGalleryModule'and a dependency uses hashtable syntax —Versionshould now be'latest'(String), not{Version, Parameters}(Hashtable).Invoke-Pester .\Tests\— 353 tests, 0 failures.PsDepend = 'latest') still works withoutDependencyTypeinPSDependOptions.🤖 Generated with Claude Code