You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is an issue in the ConvertTo-PodeYaml function in Pode that causes the conversion to fail if the source Hashtable or PSCustomObject contains a key named Count. This problem occurs due to the way the Count property is being checked during conversion, leading to conflicts when Count is a key in the object.
File:
File Name:Helper.ps1
Location:
Line 3576: if ($InputObject.Count -gt 0) {
Line 3602: if ($InputObject.Count -gt 0) {
Steps to Reproduce:
Create a Hashtable or PSCustomObject with a key named Count.
Attempt to convert the object to YAML using ConvertTo-PodeYaml.
The conversion will fail due to a conflict with the Count property being treated as a method rather than a key.
The issue arises because the Count property is being accessed directly ($InputObject.Count), which conflicts when Count is used as a key in the Hashtable or PSCustomObject. The Count property is treated as a method in such cases, causing the conversion to fail.
Fix:
The proposed solution is to adjust the conditions to avoid using the direct Count property in situations where Count could be a key.
Line 3576:
Current Code:
if ($InputObject.Count-gt0) {
Proposed Fix:
if ($hashtable.GetEnumerator().MoveNext()) {
Line 3602:
Current Code:
if ($InputObject.Count-gt0) {
Proposed Fix:
if ($InputObject.PSObject.Properties.Count-gt0) {
Additional Notes:
The fix ensures that when Count is used as a key, it will not conflict with the Count property of the object, and the conversion to YAML will work as expected.
The proposed fix uses .GetEnumerator().MoveNext() to check for the presence of elements in a Hashtable, and .PSObject.Properties.Count to properly count the properties in a PSCustomObject.
The text was updated successfully, but these errors were encountered:
mdaneri
changed the title
Issue with ConvertTo-PodeYaml when Count is a Key in Hashtable or PSCustomObject**
Issue with ConvertTo-PodeYaml when Count is a Key in Hashtable or PSCustomObject
Oct 19, 2024
Summary:
There is an issue in the
ConvertTo-PodeYaml
function in Pode that causes the conversion to fail if the sourceHashtable
orPSCustomObject
contains a key namedCount
. This problem occurs due to the way theCount
property is being checked during conversion, leading to conflicts whenCount
is a key in the object.File:
Helper.ps1
if ($InputObject.Count -gt 0) {
if ($InputObject.Count -gt 0) {
Steps to Reproduce:
Hashtable
orPSCustomObject
with a key namedCount
.ConvertTo-PodeYaml
.Count
property being treated as a method rather than a key.Example:
Root Cause:
The issue arises because the
Count
property is being accessed directly ($InputObject.Count
), which conflicts whenCount
is used as a key in theHashtable
orPSCustomObject
. TheCount
property is treated as a method in such cases, causing the conversion to fail.Fix:
The proposed solution is to adjust the conditions to avoid using the direct
Count
property in situations whereCount
could be a key.Line 3576:
Line 3602:
Additional Notes:
Count
is used as a key, it will not conflict with theCount
property of the object, and the conversion to YAML will work as expected..GetEnumerator().MoveNext()
to check for the presence of elements in aHashtable
, and.PSObject.Properties.Count
to properly count the properties in aPSCustomObject
.The text was updated successfully, but these errors were encountered: