Skip to content

Commit

Permalink
Merge pull request #139 from gabriel-samfira/fix-case-sensitive-keys
Browse files Browse the repository at this point in the history
Fix losing case sensitive keys
  • Loading branch information
gabriel-samfira authored Aug 27, 2024
2 parents 0d5b89f + 7980c7c commit 8006556
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Tests/powershell-yaml.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,13 @@ int64: 9223372036854775807
} | Should -Not -Throw
}
}

Describe 'Case insensitive keys in mappings' {
It 'should deserialize both keys' {
$yaml = '{"a": 1, "A": 2}'
$result = ConvertFrom-Yaml -Yaml $yaml
$result.a | Should -Be 1
$result.A | Should -Be 2
}
}
}
2 changes: 1 addition & 1 deletion powershell-yaml.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function Convert-YamlMappingToHashtable {
[switch] $Ordered
)
PROCESS {
if ($Ordered) { $ret = [ordered]@{} } else { $ret = @{} }
if ($Ordered) { $ret = [System.Collections.Specialized.OrderedDictionary]::new() } else { $ret = [hashtable]::new() }
foreach($i in $Node.Children.Keys) {
$ret[$i.Value] = Convert-YamlDocumentToPSObject $Node.Children[$i] -Ordered:$Ordered
}
Expand Down

0 comments on commit 8006556

Please sign in to comment.