◐ Shell
clean mode source ↗

Add `ValidateNotNullOrEmpty` attribute to the `-Property` of `Format-Table/List/Custom` by daxian-dbw · Pull Request #26552 · PowerShell/PowerShell

Pull request overview

This PR fixes issue #26543 by adding the ValidateNotNullOrEmpty attribute to the -Property parameter of Format-Table, Format-List, and Format-Custom cmdlets to prevent null reference exceptions when empty arrays or null values are passed.

Key Changes:

  • Added validation attribute to prevent null/empty Property values in Format-Table, Format-List, and Format-Custom
  • Added comprehensive test coverage for all three cmdlets verifying both null and empty array scenarios throw appropriate validation errors

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/System.Management.Automation/FormatAndOutput/common/BaseFormattingCommand.cs Added ValidateNotNullOrEmpty attribute to the Property parameter in OuterFormatTableAndListBase class, which is inherited by Format-Table and Format-List
src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-object/Format-Object.cs Added ValidateNotNullOrEmpty attribute to the Property parameter in FormatCustomCommand class
test/powershell/engine/Formatting/BugFix.Tests.ps1 Added test cases to verify that Format-Table, Format-List, and Format-Custom properly throw ParameterArgumentValidationError when Property is passed null or empty array

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.