Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public FormatCustomCommand()
/// will be determined using property sets, etc.
/// </summary>
[Parameter(Position = 0)]
[ValidateNotNullOrEmpty]
public object[] Property
{
get { return _props; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ public class OuterFormatTableAndListBase : OuterFormatShapeCommandBase
/// will be determined using property sets, etc.
/// </summary>
[Parameter(Position = 0)]
[ValidateNotNullOrEmpty]
public object[] Property { get; set; }

#endregion
Expand Down
14 changes: 14 additions & 0 deletions test/powershell/engine/Formatting/BugFix.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Loading