logstash-codec-json
logstash-codec-json copied to clipboard
Codec should not accept invalid json {}{}
The codec should not accept this input:
{ "hello": "world" }{ "goodbye": "moon" }
The above is two json objects that, alone, are valid, but combined, are not.
Expected result: Logstash should tag this event as _jsonparsefailure and store the whole payload in the message field.
Actual result: in Logstash 5.x is that the first json object is accepted and the 2nd one is lost/ignored.
diff --git a/spec/codecs/json_spec.rb b/spec/codecs/json_spec.rb
index f86f2b9..a774f7f 100644
--- a/spec/codecs/json_spec.rb
+++ b/spec/codecs/json_spec.rb
@@ -188,4 +188,15 @@ describe LogStash::Codecs::JSON do
end
end
+ context "when given invalid json" do
+ context "that looks like two jsons together" do
+ let(:text) { '{ "hello": "world" }{ "goodbye": "moon" }' }
+
+ it "should fail to parse" do
+ subject.decode(text) do |event|
+ expect(event.get("tags")).to include("_jsonparsefailure")
+ end
+ end
+ end
+ end
end
The above test reproduces this problem and fails because the expected tag is not there.