Closed mpgn closed 3 years ago
Hi!
One would expect that ConvertTo-Xml
properly handles and escapes invalid characters, but it does not as it turns out...
PS C:\> [char]0x00 | ConvertTo-Xml
ConvertTo-Xml : '.', hexadecimal value 0x00, is an invalid character.
At line:1 char:15
+ [char]0x00 | ConvertTo-Xml
+ ~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [ConvertTo-Xml], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertToXmlCommand
PS C:\> [char]0x01 | ConvertTo-Xml
ConvertTo-Xml : '☺', hexadecimal value 0x01, is an invalid character.
At line:1 char:15
+ [char]0x01 | ConvertTo-Xml
+ ~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [ConvertTo-Xml], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertToXmlCommand
PS C:\> [char]0x02 | ConvertTo-Xml
ConvertTo-Xml : '☻', hexadecimal value 0x02, is an invalid character.
At line:1 char:15
+ [char]0x02 | ConvertTo-Xml
+ ~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [ConvertTo-Xml], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.ConvertToXmlCommand
PS C:\> [char]0x41 | ConvertTo-Xml
xml Objects
--- -------
version="1.0" encoding="utf-8" Objects
I'll have to add a function for sanitizing the output before exporting to XML.
Before converting the result to XML, I now strip all the potentially invalid XML characters from the ResultRawString
member.
I found a very efficient way to do so on StackOverflow. :slightly_smiling_face:
Could you test again in the same conditions and tell me if it's ok?
Yep, fixed ! I let you the satisfaction of closing the issue :)
(also thx for the beautiful color, much better ! )
Thanks for the confirmation! :+1:
Hello
I have an issue when exporting the file using XML (only xml is buggy)
Tested on Windows server 2016 (1607), PSversion 5.1
I can provide more info if needed :)