-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Atom values obtained from Write-Output are incorrectly encoded #157
Comments
Interesting. Will have a look this evening and push a fix. |
Will also add a test case for this. Does this happen if you generate a variable from write-output and use that variable inside the hashtable before sending it to ConvertTo-Yaml? Does this happen if you pass the hashtable as an argument to ConvertTo-Yaml or does it happen only when piping? |
Yes $a = Write-Output 'test'
@{a = $a} | ConvertTo-Yaml
Yes ConvertTo-Yaml @{a = Write-Output 'test'}
|
One last test. What is the result of: ConvertTo-Yaml @{a = (Write-Output 'test')} Note the parentheses around the Write-Output command. |
The same
|
PowerShell is dark and full of terrors. I think I may know why this is happening. This will most likely work if we do an explicit cast like so: ConvertTo-Yaml @{a = [string](Write-Output 'test')} Will have a look once I get to a PC and push a fix. Thanks for testing. |
Would you mind giving : a try? |
For context, this issue happened because when we call But in this case, we have a primitive type and a string wrapped in a PS /> $aString = "test"
PS /> $aString.psobject.Properties
MemberType : Property
Value : 4
IsSettable : False
IsGettable : True
TypeNameOfValue : System.Int32
Name : Length
IsInstance : True If we pass this simple string to $aString = [pscustomobject]"test" then the |
Doesn't seem to be fixed. I have ensured it is the modified module has been loaded.
|
gah! I forgot to add a test case for IDictionary types and only fixed the pscustomobject type. Please pull the latest commit and try again. The test cases here I think should cover everything. Let me know if it works. |
It works. Thanks for your explanation and fixes!
|
Thank you for your patience and for testing! I will publish a new release on Monday. |
A new version has been released: https://www.powershellgallery.com/packages/powershell-yaml/0.4.9 A new release has been generated on GitHub: https://github.com/cloudbase/powershell-yaml/releases/tag/v0.4.9 Please test it out and let me know if all is well. |
Works well for me. |
ConvertTo-Yaml
is broken in the latest version (v0.4.8) when serializing a hashtable with atom values obtained from Write-Output. It is critical as values may be obtained from the functions that useWrite-Output
rather thanreturn
to return values.For example, when assigning with Write-Output:
the string and the number were incorrectly encoded.
while without Write-Output:
the values were correctly encoded.
The text was updated successfully, but these errors were encountered: