Skip to content
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

Fix encoding corruptions #43

Merged
merged 4 commits into from
Nov 11, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Prepend the user script with a UTF-8 BOM
  • Loading branch information
fmang committed Oct 28, 2020
commit d588a8a5bf05cb0b6fcf6fcff4bc96ccca822580
4 changes: 3 additions & 1 deletion lib/winrm/shells/elevated.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ def close

def upload_elevated_shell_script(script_text)
elevated_shell_path = 'c:/windows/temp/winrm-elevated-shell-' + SecureRandom.uuid + '.ps1'
script_text_with_exit = "#{script_text}\r\n$Host.SetShouldExit($LASTEXITCODE)"
# Prepend the content of the file with an UTF-8 BOM for Windows to read it as such instead of the default
# Windows-XXXX encoding, and convert script_text accordingly if needed.
script_text_with_exit = "\uFEFF#{script_text.encode(Encoding::UTF_8)}\r\n$Host.SetShouldExit($LASTEXITCODE)"
@winrm_file_transporter.upload(StringIO.new(script_text_with_exit), elevated_shell_path)
elevated_shell_path
end
Expand Down