Skip to content

Commit

Permalink
Encode capistrano output messages to UTF-8 before manipulating them.
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Jan 9, 2015
1 parent c6df12a commit fd44d0c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/capistrano/datadog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def report()
message_content = (@logging_output[name] || []).join('')
message = if !message_content.empty? then
# Strip out color control characters
message_content = message_content.gsub(/\e\[(\d+)m/, '')
message_content = sanitize_encoding(message_content).gsub(/\e\[(\d+)m/, '')
"@@@\n#{message_content}@@@" else "" end

Dogapi::Event.new(message,
Expand All @@ -105,6 +105,11 @@ def report()
)
end
end

def sanitize_encoding(string)
return string unless defined?(::Encoding) && string.encoding == Encoding::BINARY
string.encode(Encoding::UTF_8, Encoding::BINARY, invalid: :replace, undef: :replace, replace: '')
end
end

end
Expand Down

0 comments on commit fd44d0c

Please sign in to comment.