Skip to content

Add ValidateNotNullOrEmpty attribute to the -Property of Format-Table/List/Custom#26552

Merged
daxian-dbw merged 2 commits intoPowerShell:masterfrom
daxian-dbw:formatting
Jan 12, 2026
Merged

Add ValidateNotNullOrEmpty attribute to the -Property of Format-Table/List/Custom#26552
daxian-dbw merged 2 commits intoPowerShell:masterfrom
daxian-dbw:formatting

Conversation

@daxian-dbw
Copy link
Copy Markdown
Member

@daxian-dbw daxian-dbw commented Dec 1, 2025

PR Summary

Fix #26543

Add the ValidateNotNullOrEmpty attribute to the parameter -Property for Format-Table, Format-List, and Format-Custom.
This is to fix the null reference exception when using an empty array as the argument for -Property.

Breaking Change

It's a breaking change as today you can use $null as the argument for Format-List/Table/Custom, which behaves the same as -Property is not specified. By adding the ValidateNotNullOrEmpty attribute, -Property $null will fail. But this may fall in the bucket 3 (grey area) though.

PR Checklist

@daxian-dbw daxian-dbw added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Dec 2, 2025
@microsoft-github-policy-service microsoft-github-policy-service Bot added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Dec 5, 2025
@iSazonov iSazonov reopened this Dec 30, 2025
@iSazonov iSazonov removed the Stale label Dec 30, 2025
@microsoft-github-policy-service microsoft-github-policy-service Bot removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jan 7, 2026
@daxian-dbw daxian-dbw marked this pull request as ready for review January 7, 2026 00:25
@daxian-dbw daxian-dbw requested a review from a team as a code owner January 7, 2026 00:25
Copilot AI review requested due to automatic review settings January 7, 2026 00:25
@daxian-dbw daxian-dbw added the CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log label Jan 7, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@daxian-dbw daxian-dbw merged commit 9bc4795 into PowerShell:master Jan 12, 2026
45 checks passed
@daxian-dbw daxian-dbw deleted the formatting branch January 12, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-BreakingChange Indicates that a PR should be marked as a breaking change in the Change Log 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.

Format-* cmdlets throw NullReferenceException when -Property is an empty array

4 participants