-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Remove [ValidateNotNullOrEmpty] from -InputObject on Get-Random to allow empty string #10644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs
Show resolved
Hide resolved
src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs
Show resolved
Hide resolved
| foreach (object item in InputObject ?? _nullInArray) | ||
| { | ||
| if (_numberOfProcessedListItems < Count) // (3) | ||
| // (3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the comment for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codefactor was complaining about the trailing comment so I moved it above. If you look at the large comment above, it references (1), (2), (3) explaining the code so I left it.
|
Thanks for the quick turnaround, @SteveL-MSFT and @iSazonov. @SteveL-MSFT, to avoid confusion, could you please update the OP to indicate that |
|
It seems we need an issue in Doc repo too. |
|
@iSazonov added |
|
Hello @iSazonov! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
|
Oops, I thought AutoMerge is waiting for the day before merge 😕 |
|
🎉 Handy links: |
PR Summary
Get-Randomhas[ValidateNotNullOrEmpty]attribute onInputObjectparameter which limits a collection from having an empty string. However, if you use the default positional parameterMaximumit doesn't have this restriction. This creates confusion to users as they expect these two to be equivalent:Although it's not obvious that this is two different parameter sets. However, there's no reason to restrict
InputObjectparameter here. Since it's mandatory, you can't give it$nullonly.This change also allows
$nullin the collection:PR Context
Fix #3682
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.