Skip to content

Commit

Permalink
Fixed backwards compatibility
Browse files Browse the repository at this point in the history
Values should only be of type [array] when necessary. [string] otherwise

as mentioned by @EliaSaSe in
#43 (comment)
  • Loading branch information
lipkau committed Jan 16, 2019
1 parent 2ec97f3 commit c7b6b08
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
14 changes: 11 additions & 3 deletions PSIni/Functions/Get-IniContent.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,17 @@ Function Get-IniContent {
$name, $value = $matches[1..2]
Write-Verbose "$($MyInvocation.MyCommand.Name):: Adding key $name with value: $value"
if (-not $ini[$section][$name]) {
$ini[$section][$name] = @($value)
} else {
$ini[$section][$name] += $value
$ini[$section][$name] = $value
}
else {
if ($ini[$section][$name] -is [string]) {
$ini[$section][$name] = [System.Collections.ArrayList]::new()
$ini[$section][$name].Add($ini[$section][$name]) | Out-Null
$ini[$section][$name].Add($value) | Out-Null
}
else {
$ini[$section][$name].Add($value) | Out-Null
}
}
continue
}
Expand Down
2 changes: 1 addition & 1 deletion PSIni/PsIni.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
Description = 'Convert hashtable to INI file and back. @ http://lipkau.github.io/PsIni/'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '2.0'
PowerShellVersion = '3.0'

# Name of the Windows PowerShell host required by this module
PowerShellHostName = ''
Expand Down
17 changes: 15 additions & 2 deletions Tests/PsIni.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ Describe "PsIni functionality" {

Context "Reading INI" {

# act
#arrange
Out-IniFile -InputObject $dictIn -FilePath $iniFile
$dictOut = Get-IniContent -FilePath $iniFile

# act
$global:dictOut = Get-IniContent -FilePath $iniFile

# assert
It "creates a OrderedDictionary from an INI file" {
Expand All @@ -115,6 +117,17 @@ Describe "PsIni functionality" {
Compare-Object $dictIn $dictOut
}

#assert
It "reads sames keys into an [array]" {
$dictOut["Category2"]["Key3"].gettype().FullName | Should -Be "System.Collections.ArrayList"
}

It "keeps non repeating keys as [string]" {
$dictOut["Category1"]["Key1"] | Should -BeOfType [String]
$dictOut["Category1"]["Key2"] | Should -BeOfType [String]
$dictOut["Category2"]["Key4"] | Should -BeOfType [String]
}

}

Context "Updating INI Content" {
Expand Down

0 comments on commit c7b6b08

Please sign in to comment.