Small fix for logstash/event.rb's sprintf method.

I found this with the riemann output - if you set it up with:
riemann_event => [ 'metric', 0 ]

Then the value gets sprintf'd, which utterly fails in this unquoted case, as 0
is a Fixnum, which doesn't have an index method.

This, we explicitly call .to_s in the sprintf method, to ensure that the
format is a string before call .index on it
This commit is contained in:
Tomas Doran 2013-07-25 19:51:25 -07:00
parent de91e8fa18
commit 2830015267
2 changed files with 5 additions and 0 deletions

View file

@ -201,6 +201,7 @@ class LogStash::Event
# is an array (or hash?) should be. Join by comma? Something else?
public
def sprintf(format)
format = format.to_s
if format.index("%").nil?
return format
end

View file

@ -45,6 +45,10 @@ describe LogStash::Event do
insist { subject.sprintf("%{[j][k1]}") } == "v"
insist { subject.sprintf("%{[j][k2][0]}") } == "w"
end
it "should be able to take a non-string for the format" do
insist { subject.sprintf(2) } == "2"
end
end
context "#[]" do