class WinRM::WSMV::CommandOutputDecoder
Handles decoding a raw output response
Public Instance Methods
decode(raw_output)
click to toggle source
Decode the raw SOAP
output into decoded and human consumable text, Decodes and replaces invalid unicode characters. @param raw_output [String] The raw encoded output @return [String] The decoded output
# File lib/winrm/wsmv/command_output_decoder.rb, line 25 def decode(raw_output) decoded_text = decode_raw_output(raw_output) decoded_text = handle_invalid_encoding(decoded_text) decoded_text = remove_bom(decoded_text) decoded_text end
Private Instance Methods
decode_raw_output(raw_output)
click to toggle source
# File lib/winrm/wsmv/command_output_decoder.rb, line 34 def decode_raw_output(raw_output) Base64.decode64(raw_output).force_encoding('utf-8') end
handle_invalid_encoding(decoded_text)
click to toggle source
# File lib/winrm/wsmv/command_output_decoder.rb, line 38 def handle_invalid_encoding(decoded_text) return decoded_text if decoded_text.valid_encoding? if decoded_text.respond_to?(:scrub) decoded_text.scrub else decoded_text.encode('utf-16', invalid: :replace, undef: :replace).encode('utf-8') end end
remove_bom(decoded_text)
click to toggle source
# File lib/winrm/wsmv/command_output_decoder.rb, line 48 def remove_bom(decoded_text) # remove BOM which 2008R2 applies decoded_text.sub("\xEF\xBB\xBF", '') end