diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CSVCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CSVCommands.cs index a37c8f9d00b..2f86c324e6b 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CSVCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/CSVCommands.cs @@ -1610,9 +1610,12 @@ private void { string name = names[i]; string value = null; - ////if name is null and delimiter is '"', continue + ////if name is null and delimiter is '"', use a default property name 'UnspecifiedName' if (name.Length == 0 && delimiterlocal == '"') - continue; + { + name = UnspecifiedName + unspecifiedNameIndex; + unspecifiedNameIndex++; + } ////if name is null and delimiter is not '"', use a default property name 'UnspecifiedName' if (string.IsNullOrEmpty(name)) { diff --git a/src/System.Management.Automation/engine/InitialSessionState.cs b/src/System.Management.Automation/engine/InitialSessionState.cs index 701d9f0a856..8c4cc0d0e21 100644 --- a/src/System.Management.Automation/engine/InitialSessionState.cs +++ b/src/System.Management.Automation/engine/InitialSessionState.cs @@ -1842,10 +1842,13 @@ public Microsoft.PowerShell.ExecutionPolicy ExecutionPolicy /// /// The modules to add /// - public void ImportPSModule(string[] name) + public void ImportPSModule(params string[] name) { if (name == null) + { throw new ArgumentNullException("name"); + } + foreach (string n in name) { ModuleSpecificationsToImport.Add(new ModuleSpecification(n)); diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Csv.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Csv.Tests.ps1 index e707cb3a0f0..3c2316fa113 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Csv.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/Import-Csv.Tests.ps1 @@ -22,6 +22,38 @@ Describe "Import-Csv DRT Unit Tests" -Tags "CI" { } } +Describe "Import-Csv Double Quote Delimiter" -Tags "CI" { + BeforeAll { + $empyValueCsv = @' + a1""a3 + v1"v2"v3 +'@ + + $withValueCsv = @' + a1"a2"a3 + v1"v2"v3 +'@ + + $quotedCharacterCsv = @' + a1,a2,a3 + v1,"v2",v3 +'@ + } + + + It "Should handle " -TestCases @( + @{ name = "quote with empty value" ; expectedHeader = "a1,H1,a3"; file = "EmptyValue.csv" ; content = $empyValueCsv ; delimiter = '"' } + @{ name = "quote with value" ; expectedHeader = "a1,a2,a3"; file = "WithValue.csv" ; content = $withValueCsv ; delimiter = '"' } + @{ name = "value enclosed in quote" ; expectedHeader = "a1,a2,a3"; file = "QuotedCharacter.csv" ; content = $quotedCharacterCsv ; delimiter = ',' } + ){ + param($expectedHeader, $file, $content, $delimiter) + Set-Content testdrive:/$file -Value $content + $returnObject = Import-Csv -Path testdrive:/$file -Delimiter $delimiter + $actualHeader = $returnObject[0].psobject.Properties.name -join ',' + $actualHeader | Should -Be $expectedHeader + } +} + Describe "Import-Csv File Format Tests" -Tags "CI" { BeforeAll { # The file is w/o header