mirror of
https://github.com/elastic/logstash.git
synced 2025-06-28 01:37:28 -04:00
Validate the size limit in BufferedTokenizer. (#16882)
This commit is contained in:
parent
d978e07f2c
commit
a215101032
3 changed files with 10 additions and 2 deletions
|
@ -12,7 +12,6 @@ import org.openjdk.jmh.annotations.Fork;
|
||||||
import org.openjdk.jmh.annotations.Level;
|
import org.openjdk.jmh.annotations.Level;
|
||||||
import org.openjdk.jmh.annotations.Measurement;
|
import org.openjdk.jmh.annotations.Measurement;
|
||||||
import org.openjdk.jmh.annotations.Mode;
|
import org.openjdk.jmh.annotations.Mode;
|
||||||
import org.openjdk.jmh.annotations.OperationsPerInvocation;
|
|
||||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||||
import org.openjdk.jmh.annotations.Scope;
|
import org.openjdk.jmh.annotations.Scope;
|
||||||
import org.openjdk.jmh.annotations.Setup;
|
import org.openjdk.jmh.annotations.Setup;
|
||||||
|
|
|
@ -61,6 +61,11 @@ describe FileWatch::BufferedTokenizer do
|
||||||
context 'with decode_size_limit_bytes' do
|
context 'with decode_size_limit_bytes' do
|
||||||
subject { FileWatch::BufferedTokenizer.new("\n", 100) }
|
subject { FileWatch::BufferedTokenizer.new("\n", 100) }
|
||||||
|
|
||||||
|
it "validates size limit" do
|
||||||
|
expect { FileWatch::BufferedTokenizer.new("\n", -101) }.to raise_error(java.lang.IllegalArgumentException, "Size limit must be positive")
|
||||||
|
expect { FileWatch::BufferedTokenizer.new("\n", 0) }.to raise_error(java.lang.IllegalArgumentException, "Size limit must be positive")
|
||||||
|
end
|
||||||
|
|
||||||
it "emits the contents of the buffer" do
|
it "emits the contents of the buffer" do
|
||||||
expect(subject.flush).to eq(data)
|
expect(subject.flush).to eq(data)
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,7 +55,11 @@ public class BufferedTokenizerExt extends RubyObject {
|
||||||
this.delimiter = args[0].convertToString();
|
this.delimiter = args[0].convertToString();
|
||||||
}
|
}
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
this.sizeLimit = args[1].convertToInteger().getIntValue();
|
final int sizeLimit = args[1].convertToInteger().getIntValue();
|
||||||
|
if (sizeLimit <= 0) {
|
||||||
|
throw new IllegalArgumentException("Size limit must be positive");
|
||||||
|
}
|
||||||
|
this.sizeLimit = sizeLimit;
|
||||||
this.hasSizeLimit = true;
|
this.hasSizeLimit = true;
|
||||||
}
|
}
|
||||||
this.inputSize = 0;
|
this.inputSize = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue