Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name>" -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

Usualy we do this in BeforeAll block. Then we could pass only file name to the block.

Copy link
Member

Choose a reason for hiding this comment

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

Having it in BeforeAll makes sense if multiple tests use the same test content, but in this case only this test uses them so I think it's ok to just have it here closer to the test code.

$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
Expand Down