Skip to content

Commit 42b126d

Browse files
jsvdlogstashmachine
authored andcommitted
ensure inputSize state value is reset during buftok.flush (#16760)
(cherry picked from commit e36cace)
1 parent 6f8fd5a commit 42b126d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

logstash-core/spec/logstash/util/buftok_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,35 @@
4343
expect(subject.extract("\n\n\n")).to eq(["", "", ""])
4444
end
4545

46+
describe 'flush' do
47+
let(:data) { "content without a delimiter" }
48+
before(:each) do
49+
subject.extract(data)
50+
end
51+
52+
it "emits the contents of the buffer" do
53+
expect(subject.flush).to eq(data)
54+
end
55+
56+
it "resets the state of the buffer" do
57+
subject.flush
58+
expect(subject).to be_empty
59+
end
60+
61+
context 'with decode_size_limit_bytes' do
62+
subject { FileWatch::BufferedTokenizer.new("\n", 100) }
63+
64+
it "emits the contents of the buffer" do
65+
expect(subject.flush).to eq(data)
66+
end
67+
68+
it "resets the state of the buffer" do
69+
subject.flush
70+
expect(subject).to be_empty
71+
end
72+
end
73+
end
74+
4675
context 'with delimiter' do
4776
subject { FileWatch::BufferedTokenizer.new(delimiter) }
4877

logstash-core/src/main/java/org/logstash/common/BufferedTokenizerExt.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,13 @@ public RubyArray extract(final ThreadContext context, IRubyObject data) {
106106
public IRubyObject flush(final ThreadContext context) {
107107
final IRubyObject buffer = input.join(context);
108108
input.clear();
109+
inputSize = 0;
109110
return buffer;
110111
}
111112

112113
@JRubyMethod(name = "empty?")
113114
public IRubyObject isEmpty(final ThreadContext context) {
114-
return input.empty_p();
115+
return RubyUtil.RUBY.newBoolean(input.isEmpty() && (inputSize == 0));
115116
}
116117

117118
}

0 commit comments

Comments
 (0)