Fix UseCulture: behavior for CSV delimiter #26513#26551
Fix UseCulture: behavior for CSV delimiter #26513#26551blanca-negrete wants to merge 1 commit intoPowerShell:masterfrom
Conversation
| else | ||
| { | ||
| delimiter = ImportExportCSVHelper.CSVDelimiter; | ||
| } |
There was a problem hiding this comment.
Please use conditional operator.
delimiter = useCulture ? ... : ...|
The PR needs to be marked as fixing issue: |
|
This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where ConvertTo-Csv and Export-Csv incorrectly used the culture-specific delimiter even when explicitly passed -UseCulture:$false. The fix ensures that when UseCulture is explicitly set to $false, the commands correctly fall back to the default comma (,) delimiter instead of using the culture-specific list separator.
Key Changes
- Added an
elseblock inImportExportCSVHelper.SetDelimiterto handle the case whenuseCultureisfalse, ensuring it falls back to the default CSV delimiter (comma)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| else | ||
| { | ||
| delimiter = ImportExportCSVHelper.CSVDelimiter; | ||
| } |
There was a problem hiding this comment.
This fix for handling UseCulture:$false correctly lacks test coverage. While the fix itself is correct, automated tests should be added to verify that:
- When -UseCulture:$false is explicitly specified, the default comma delimiter is used (not the culture-specific delimiter)
- When -UseCulture is omitted, the default comma delimiter is used
- When -UseCulture or -UseCulture:$true is specified, the culture-specific delimiter is used
These tests would prevent regression of issue #26513 and can be added to the existing test files (e.g., ConvertTo-Csv.Tests.ps1 or ImportExportCSV.Delimiter.Tests.ps1).
PR Summary
Fix #26513
Fixes behavior where ConvertTo-Csv and Export-Csv incorrectly used the culture-specific delimiter even when explicitly passed -UseCulture:$false. When UseCulture is set to $false, the commands now correctly fall back to the default comma (,) delimiter.
PR Context
-UseCulture:$false was not being treated the same as omitting -UseCulture.
This resulted in inconsistent delimiter behavior, especially in cultures that use ; as the list separator.
This PR updates ImportExportCSVHelper.SetDelimiter to ensure that UseCulture:$false properly defaults to the standard CSV delimiter.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header