Fix for ConvertTo-PodeYaml failing, when passed object contains a Key named "Count" #1418
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.