Add validation to prevent duplicate alias names and definitions#27505
Open
jserygit wants to merge 2 commits into
Open
Add validation to prevent duplicate alias names and definitions#27505jserygit wants to merge 2 commits into
jserygit wants to merge 2 commits into
Conversation
…me in NewAliasCommand and SetAliasCommand
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds validation to prevent creating or setting an alias whose name is the same as its definition (case-insensitive), returning an error instead.
Changes:
- Added a self-referential alias guard (
Name == Definition, ignoring case) inSet-AliasandNew-Alias. - Added
using System;to supportStringComparison.OrdinalIgnoreCase.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Microsoft.PowerShell.Commands.Utility/commands/utility/SetAliasCommand.cs | Rejects self-referential alias updates before attempting to set the alias. |
| src/Microsoft.PowerShell.Commands.Utility/commands/utility/NewAliasCommand.cs | Rejects self-referential alias creation before attempting to create the alias. |
Author
|
@microsoft-github-policy-service agree |
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.
PR Summary
Add validation to prevent users from creating or setting a PowerShell alias with the same name as its definition, which would be invalid.
The main changes introduce this check in both the
NewAliasCommandandSetAliasCommandimplementations.Validation improvements for alias commands:
NewAliasCommandto ensure the alias name and its definition are not the same, and to write an error if this occurs.SetAliasCommandto prevent setting an alias where the name matches the definition, also writing an error in this case.General code updates:
using System;directive to bothNewAliasCommand.csandSetAliasCommand.csto support the new validation logic.Fix #20153
PR Context
Creating or updating an alias where the alias Name is identical to its Value can result in the alias being created but then failing every time it is invoked.
This yields confusing runtime errors and an inconsistent state (alias created but unusable).
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header