[release/v7.5] Handle null reference exception in CsvCommands.cs: ConvertPSObjectToCSV#26394
[release/v7.5] Handle null reference exception in CsvCommands.cs: ConvertPSObjectToCSV#26394TravisEz13 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a NullReferenceException when exporting hashtables with null property values to CSV format. The fix adds a null-conditional operator to safely handle null dictionary values.
- Adds null-conditional operator (
?.) when callingToString()on dictionary values - Adds test coverage for exporting hashtables and PSCustomObjects with null values
- Verifies that the CSV export correctly represents null values as empty fields
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Microsoft.PowerShell.Commands.Utility/commands/utility/CsvCommands.cs |
Adds null-conditional operator to prevent NullReferenceException when dictionary contains null values |
test/powershell/Modules/Microsoft.PowerShell.Utility/Export-Csv.Tests.ps1 |
Adds tests to verify Export-Csv handles null values in hashtables correctly |
test/powershell/Modules/Microsoft.PowerShell.Utility/ConvertTo-Csv.Tests.ps1 |
Adds test for ConvertTo-Csv with hashtable containing null values |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
|
I don't think this meets the bar to go back to 7.5 as it was not a regression. |
|
@TravisEz13 - I recognize that we're imminently close to v7.6 release, but it is still preview. Is the "bar" documented somewhere? Not intending to be rude - just for my edification. |
|
|
|
@daxian-dbw - is the decision-making process here for what is backported or not documented somewhere? Or is it simply "if we didn't break it, we won't fix it until a future release" (e.g. no regression)? I know of at least one person experiencing this annoyance in 7.5, and if it's true it didn't make 7.6-rc, that's disappointing as well. |
|
I don't think it's documented anywhere, but the bar is high -- usually only regressions in that particular release or security fixes. |
|
Closing this PR, but leave the original PR #26144 labelled as |
Backport of #26144 to release/v7.5
Triggered by @TravisEz13 on behalf of @mikkas456
Original CL Label: CL-General
/cc @PowerShell/powershell-maintainers
Impact
Customer Impact
This PR backports a fix for a null reference exception in CSV commands. The original PR addresses a bug where ConvertPSObjectToCSV would throw a null reference exception when processing certain objects. This improves reliability and prevents crashes when working with CSV data.
Regression
This is a bug fix, not a regression fix.
Testing
The original PR included test cases to verify the null reference handling. The fix was validated through unit tests that cover the edge case scenarios. The backport maintains the same test coverage.
Risk
This is a targeted bug fix with a narrow scope. The change only affects error handling in the CSV conversion logic and includes test coverage. The risk is low as it prevents exceptions without changing the core functionality of CSV commands.