mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add ValidateNotNullOrEmpty attribute to the -Property of Format-Table/List/Custom (#26552)
This commit is contained in:
+1
@@ -32,6 +32,7 @@ namespace Microsoft.PowerShell.Commands
|
||||
/// will be determined using property sets, etc.
|
||||
/// </summary>
|
||||
[Parameter(Position = 0)]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public object[] Property
|
||||
{
|
||||
get { return _props; }
|
||||
|
||||
@@ -728,6 +728,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
|
||||
/// will be determined using property sets, etc.
|
||||
/// </summary>
|
||||
[Parameter(Position = 0)]
|
||||
[ValidateNotNullOrEmpty]
|
||||
public object[] Property { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -63,3 +63,17 @@ Describe "Hidden properties should not be returned by the 'FirstOrDefault' primi
|
||||
$outstring.Trim() | Should -BeExactly "Param$([System.Environment]::NewLine)-----$([System.Environment]::NewLine)Foo"
|
||||
}
|
||||
}
|
||||
|
||||
Describe "'Format-Table/List/Custom -Property' should not throw NullRef exception" -Tag CI {
|
||||
|
||||
It "'<Command> -Property' requires value to be not null and not empty" -TestCases @(
|
||||
@{ Command = "Format-Table"; NameInErrorId = "FormatTableCommand" }
|
||||
@{ Command = "Format-List"; NameInErrorId = "FormatListCommand" }
|
||||
@{ Command = "Format-Custom"; NameInErrorId = "FormatCustomCommand" }
|
||||
) {
|
||||
param($Command, $NameInErrorId)
|
||||
|
||||
{ Get-Process -Id $PID | & $Command -Property @() } | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.$NameInErrorId"
|
||||
{ Get-Process -Id $PID | & $Command -Property $null } | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.$NameInErrorId"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user