This pull request addresses the issue described in Bug #1417, where ConvertTo-PodeYaml fails when the source Hashtable or PSCustomObject contains a key named 'Count'.
Issue Description
The ConvertTo-PodeYaml function incorrectly assumes that .Count refers to the number of elements in the object, which causes a conflict if the object contains a key named 'Count'. This results in a failure during the YAML conversion process.
Affected File
File: Helper.ps1
Lines:
Line 3576: if ($InputObject.Count -gt 0 )
Line 3602: if ($InputObject.Count -gt 0 )
Proposed Fix
To avoid conflicts with the 'Count' key, the following changes have been made:
Line 3576: Replaced with if ($InputObject.GetEnumerator().MoveNext())
Line 3602: Replaced with if ($InputObject.PSObject.Properties.Count -gt 0)
Code Changes
- if ($InputObject.Count -gt 0 ) {
+ if ($InputObject.GetEnumerator().MoveNext()) {
- if ($InputObject.Count -gt 0 ) {
+ if ($InputObject.PSObject.Properties.Count -gt 0) {
Testing
The issue has been reproduced with a Hashtable and PSCustomObject containing a key named 'Count'. After applying the fix, the ConvertTo-PodeYaml function works as expected without any errors.
Issue Reference
This pull request addresses the issue described in Bug #1417, where
ConvertTo-PodeYaml
fails when the sourceHashtable
orPSCustomObject
contains a key named'Count'
.Issue Description
The
ConvertTo-PodeYaml
function incorrectly assumes that.Count
refers to the number of elements in the object, which causes a conflict if the object contains a key named'Count'
. This results in a failure during the YAML conversion process.Affected File
Helper.ps1
if ($InputObject.Count -gt 0 )
if ($InputObject.Count -gt 0 )
Proposed Fix
To avoid conflicts with the
'Count'
key, the following changes have been made:if ($InputObject.GetEnumerator().MoveNext())
if ($InputObject.PSObject.Properties.Count -gt 0)
Code Changes
Testing
The issue has been reproduced with a
Hashtable
andPSCustomObject
containing a key named'Count'
. After applying the fix, theConvertTo-PodeYaml
function works as expected without any errors.Example of Reproducing the Issue
Before the fix:
This would throw an error due to the key
'Count'
.After the fix, the same command should successfully convert the object to YAML.