String Interpolation skip the last character

This PR fix a problem when doing the interpolation with a string that
did not end with a fieldref but with a character. The interpolation was
ignoring the last character.

Example:
```
"%{type}|" => "syslog"
```

Fixes #3931

Fixes #3937
This commit is contained in:
Pier-Hugues Pellerin 2015-09-17 12:29:29 -04:00 committed by Jordan Sissel
parent 7f9e81727d
commit 935ac9285b
2 changed files with 5 additions and 1 deletions

View file

@ -46,7 +46,7 @@ module LogStash
position = match.offset(0).last
end
if position < template.size - 1
if position < template.size
nodes << StaticNode.new(template[position..-1])
end

View file

@ -100,6 +100,10 @@ describe LogStash::Event do
expect(subject.sprintf("%{[j][k3]}")).to eq("{\"4\":\"m\"}")
end
it "should not strip last character" do
expect(subject.sprintf("%{type}%{message}|")).to eq("sprintfhello world|")
end
context "#encoding" do
it "should return known patterns as UTF-8" do
expect(subject.sprintf("%{message}").encoding).to eq(Encoding::UTF_8)