ensure all strings pulled out of ENV are UTF8 on windows

strings assigned to LogStash::Event fields must be UTF-8 and
since most windows aren't UTF-8 by default we must intercept all
get operations and convert the strings to UTF-8. Issue surfaces in
logstash-filter-environment, for example.

Fixes #2666
This commit is contained in:
Joao Duarte 2015-02-23 09:26:30 +00:00 committed by Jordan Sissel
parent e5c78c7c66
commit 6230084c20

View file

@ -32,3 +32,19 @@ if LogStash::Environment.windows? && LogStash::Environment.jruby?
include JRubyBug2558SocketPeerAddrBugFix
end
end
if LogStash::Environment.windows?
# make sure all strings pulled out of ENV are UTF8
class <<ENV
alias_method :orig_getter, :[]
def [](key)
case value = orig_getter(key)
when String
# dup is necessary since force_encoding is destructive
value.dup.force_encoding(Encoding::UTF_8)
else
value
end
end
end
end