mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
makes sure that all property interpolation throught event.sprintf are returned in UTF-8
Fixes #3718
This commit is contained in:
parent
0d70995306
commit
45e768e833
2 changed files with 15 additions and 5 deletions
|
@ -17,9 +17,9 @@ module LogStash
|
|||
if template.is_a?(Float) && (template < MIN_FLOAT_BEFORE_SCI_NOT || template >= MAX_FLOAT_BEFORE_SCI_NOT)
|
||||
return ("%.15f" % template).sub(/0*$/,"")
|
||||
end
|
||||
|
||||
|
||||
template = template.to_s
|
||||
|
||||
|
||||
return template if not_cachable?(template)
|
||||
|
||||
compiled = CACHE.get_or_default(template, nil) || CACHE.put(template, compile_template(template))
|
||||
|
@ -108,11 +108,11 @@ module LogStash
|
|||
|
||||
case value
|
||||
when nil
|
||||
"%{#{@key}}"
|
||||
"%{#{@key}}".encode(Encoding::UTF_8)
|
||||
when Array
|
||||
value.join(",")
|
||||
value.join(",").encode(Encoding::UTF_8)
|
||||
when Hash
|
||||
LogStash::Json.dump(value)
|
||||
LogStash::Json.dump(value).encode(Encoding::UTF_8)
|
||||
else
|
||||
value
|
||||
end
|
||||
|
|
|
@ -99,6 +99,16 @@ describe LogStash::Event do
|
|||
it "should return a json string if the key is a hash" do
|
||||
expect(subject.sprintf("%{[j][k3]}")).to eq("{\"4\":\"m\"}")
|
||||
end
|
||||
|
||||
context "#encoding" do
|
||||
it "should return known patterns as UTF-8" do
|
||||
expect(subject.sprintf("%{message}").encoding).to eq(Encoding::UTF_8)
|
||||
end
|
||||
|
||||
it "should return unknown patterns as UTF-8" do
|
||||
expect(subject.sprintf("%{unkown_pattern}").encoding).to eq(Encoding::UTF_8)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#[]" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue