monkeypatch Socket on jruby+windows to return UTF-8 strings

Fixes #2507
This commit is contained in:
Joao Duarte 2015-02-06 18:23:43 +00:00 committed by Jordan Sissel
parent c4a6f41ca6
commit 6b15234b9e
3 changed files with 35 additions and 1 deletions

View file

@ -296,7 +296,6 @@ class LogStash::Event
def self.validate_value(value)
case value
when String
value.force_encoding("UTF-8") if LogStash::Environment.windows?
raise("expected UTF-8 encoding for value=#{value}, encoding=#{value.encoding.inspect}") unless value.encoding == Encoding::UTF_8
raise("invalid UTF-8 encoding for value=#{value}, encoding=#{value.encoding.inspect}") unless value.valid_encoding?
value

View file

@ -0,0 +1,34 @@
require "logstash/environment"
if LogStash::Environment.windows? && LogStash::Environment.jruby? then
require "socket"
module JRubyBug2558SocketPeerAddrBugFix
def peeraddr
orig_peeraddr.map do |v|
case v
when String
v.force_encoding(Encoding::UTF_8)
else
v
end
end
end
end
class << Socket
# Bugfix for jruby #2558
alias_method :orig_gethostname, :gethostname
def gethostname
return orig_gethostname.force_encoding(Encoding::UTF_8)
end
end
class TCPSocket
alias_method :orig_peeraddr, :peeraddr
include JRubyBug2558SocketPeerAddrBugFix
end
class UDPSocket
alias_method :orig_peeraddr, :peeraddr
include JRubyBug2558SocketPeerAddrBugFix
end
end

View file

@ -45,6 +45,7 @@ if ENV["PROFILE_BAD_LOG_CALLS"] || $DEBUGLIST.include?("log")
end
end # PROFILE_BAD_LOG_CALLS
require "logstash/monkeypatches-for-bugs"
require "logstash/monkeypatches-for-debugging"
require "logstash/namespace"
require "logstash/program"