Search code examples
regexxmlpowershellxsltansi

How to escape/ translate Encoding/chars via Regex and XSLT?


I need some help on how to actually fix these encoding being outputted as special characters in an xml.I'm trying to execute a powershell script to create a certificate using a platform via an SSH connection on a server and the expected response from it is a clean xml form but unfortunately this special character issue is happening.I might need to do an xslt and regex as a workaround to fix the xml:

     <output>
        <line index="1">(B)0[?7l[H[J[3;1H    Directory: D:\Certificatesdev[6;1HMode               </line>
        <line index="2">[24;1H                                                                                [24;1H-----------------------------------------------------------------------------[24;1H</line>
        <line index="3">[24;1H                                                                                [24;1HSign Certificate: Successful[24;1H</line>
        <line index="4">[24;1H                                                                                [24;1H-----------------------------------------------------------------------------[24;1H</line>
        <line index="5">[24;1H                                                                                [24;1HEvent Summary:[24;1H</line>
        <line index="6">[24;1H                                                                                [24;1H*Generate Sign Certificate File: Passed[24;1H</line>
        <line index="7">[24;1H                                                                                [24;1H</line>
        <line index="8">[24;1H                                                                                [23;1HGenerated D:\Certificatesdev\Folder\test.com-20150511-210523.[24;1Hcer[24;1H</line>
        <line index="9">[24;1H                                                                                [24;1H*Get Actual Certificate Expiry Date: Passed[24;1H</line>
        <line index="10">[24;1H                                                                                [24;1H*Copy to Shared Folder: Passed[24;1H</line>
        <line index="11">[24;1H                                                                                [24;1H</line>
        <line index="12">[24;1H                                                                                [23;1HFile Location: D:\Certificatesdev\Folder\test.com-20150511-21[24;1H0523[24;1H</line>
        <line index="13">[24;1H                                                                                [24;1H*Add to Certificate DB: Successful[24;1H</line>
        <line index="14">[24;1H                                                                                [24;1HCertificate Automation Completed Successfully[24;1H</line>
        <line index="15">[24;1H                                                                                [24;1H</line>
        <line index="16">[24;1H                                                                                [24;1H</line>
        <line index="17">[24;1H                                                                                [24;1H[?7h</line>
      </output>

Note that the extra spaces are not expected as well. I am not quite sure what kind of encoding is this. Please Help. Thank you


Solution

  • I'm denis bider from Bitvise. My attention is called to this because I understand the issue you're experiencing happens when connecting to a version of WinSSHD or Bitvise SSH Server.

    If I understand correctly, you're connecting to the SSH Server in order to receive from it an XML type of file. It looks like the way you are connecting to the SSH Server and retrieving data uses either an exec request, or a terminal shell session.

    The issue appears to be that when you receive data on the client side, you are expecting a plain stream of data, but what you're receiving instead are terminal escape sequences. This appears to be because your SSH client, when connecting to the server, requests terminal emulation.

    The best way to resolve this issue would be either to:

    • change SSH client parameters so that it does NOT request a terminal (such as vt100 or xterm) when connecting to the server, or that it requests the "dumb" terminal type instead;

    • or alternately, if the SSH client is of a type that does not allow changing the terminal being requested, the SSH Server supports a setting that allows you to force it to use the "dumb" terminal type (no escape sequences), no matter what the client requests.

    If you are looking to change this via the server-side setting, you can find it in SSH Server settings, either in the account or group settings entry that contains settings for this user. The name of the setting is "Always use 'dumb' pseudo terminal".