mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
monkeypatch Socket on jruby+windows to return UTF-8 strings
Fixes #2507
This commit is contained in:
parent
24ba3641b7
commit
dca895f747
3 changed files with 35 additions and 1 deletions
|
@ -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
|
||||
|
|
34
lib/logstash/monkeypatches-for-bugs.rb
Normal file
34
lib/logstash/monkeypatches-for-bugs.rb
Normal 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
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue