Skip to content

Commit

Permalink
inputs/base: Copy the codec's charset when switching.
Browse files Browse the repository at this point in the history
Includes tests
  • Loading branch information
jordansissel committed Jul 14, 2014
1 parent bf518f7 commit ea350aa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/logstash/inputs/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ def fix_streaming_codecs
case @codec
when LogStash::Codecs::Plain
@logger.info("Automatically switching from #{@codec.class.config_name} to line codec", :plugin => self.class.config_name)
@codec = LogStash::Codecs::Line.new
@codec = LogStash::Codecs::Line.new("charset" => @codec.charset)
when LogStash::Codecs::JSON
@logger.info("Automatically switching from #{@codec.class.config_name} to json_lines codec", :plugin => self.class.config_name)
@codec = LogStash::Codecs::JSONLines.new
@codec = LogStash::Codecs::JSONLines.new("charset" => @codec.charset)
end
end
end # class LogStash::Inputs::Base
13 changes: 13 additions & 0 deletions spec/inputs/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# encoding: utf-8
require "test_utils"

describe "LogStash::Inputs::Base#fix_streaming_codecs" do
it "should carry the charset setting along when switching" do
require "logstash/inputs/tcp"
require "logstash/codecs/plain"
plain = LogStash::Codecs::Plain.new("charset" => "CP1252")
tcp = LogStash::Inputs::Tcp.new("codec" => plain, "port" => 3333)
tcp.instance_eval { fix_streaming_codecs }
insist { tcp.codec.charset } == "CP1252"
end
end

0 comments on commit ea350aa

Please sign in to comment.