8000 Remove [ValidateNotNullOrEmpty] from -InputObject on Get-Random to allow empty string by SteveL-MSFT · Pull Request #10644 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@SteveL-MSFT
Copy link
Member
@SteveL-MSFT SteveL-MSFT commented Sep 28, 2019

PR Summary

Get-Random has [ValidateNotNullOrEmpty] attribute on InputObject parameter which limits a collection from having an empty string. However, if you use the default positional parameter Maximum it doesn't have this restriction. This creates confusion to users as they expect these two to be equivalent:

Get-Random @('a','') # this already worked
Get-Random -InputObject @('a','')

Although it's not obvious that this is two different parameter sets. However, there's no reason to restrict InputObject parameter here. Since it's mandatory, you can't give it $null only.

This change also allows $null in the collection:

Get-Random @('a',$null) # this already worked
Get-Random -InputObject @(`a`,$null)

PR Context

Fix #3682

PR Checklist

foreach (object item in InputObject ?? _nullInArray)
{
if (_numberOfProcessedListItems < Count) // (3)
// (3)
Copy link
Collaborator

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?

Copy link
Member Author

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.

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Sep 30, 2019
@iSazonov iSazonov added this to the 7.0.0-preview.5 milestone Sep 30, 2019
@mklement0
Copy link
Contributor

Thanks for the quick turnaround, @SteveL-MSFT and @iSazonov.

@SteveL-MSFT, to avoid confusion, could you please update the OP to indicate that $null values in the input collection now are accepted (in addition to empty strings)?

@iSazonov iSazonov added the Documentation Needed in this repo Documentation is needed in this repo label Oct 1, 2019
@iSazonov
Copy link
Collaborator
iSazonov commented Oct 1, 2019

It seems we need an issue in Doc repo too.

@SteveL-MSFT
Copy link
Member Author

@iSazonov added

@iSazonov iSazonov added AutoMerge informs the bot to automerge the PR and removed Documentation Needed in this repo Documentation is needed in this repo labels Oct 1, 2019
@ghost
Copy link
ghost commented Oct 1, 2019

Hello @iSazonov!

Because this pull request has the AutoMerge label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

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 (@msftbot) and give me an instruction to get started! Learn more here.

@ghost ghost merged commit d8eca6a into PowerShell:master Oct 1, 2019
@iSazonov
Copy link
Collaborator
iSazonov commented Oct 1, 2019

Oops, I thought AutoMerge is waiting for the day before merge 😕

@ghost
Copy link
ghost commented Oct 23, 2019

🎉v7.0.0-preview.5 has been released which incorporates this pull request.:tada:

Handy links:

@SteveL-MSFT SteveL-MSFT deleted the get-random branch June 6, 2020 02:31
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AutoMerge informs the bot to automerge the PR CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strange Get-Random Input-Object parameter behaviour

4 participants

0