diff --git a/ext/yajl/yajl_ext.c b/ext/yajl/yajl_ext.c index dc31f7c2..a8faea0f 100644 --- a/ext/yajl/yajl_ext.c +++ b/ext/yajl/yajl_ext.c @@ -792,7 +792,7 @@ static void rb_yajl_projector_ignore_value(yajl_event_stream_t parser) { return; } - rb_raise(cStandardError, "unknown value type to ignore %s", yajl_tok_name(value_event.token)); + rb_raise(cParseError, "unknown value type to ignore %s", yajl_tok_name(value_event.token)); } /* diff --git a/spec/projection/projection.rb b/spec/projection/projection.rb index 0e15f750..9558507c 100644 --- a/spec/projection/projection.rb +++ b/spec/projection/projection.rb @@ -42,6 +42,39 @@ }.to raise_error(Yajl::ParseError) end + it "should behave the same way as the regular parser on bad tokens like comma" do + bad_json = '{"name": "keith", "age":, 27}' + stream = StringIO.new(bad_json) + projector = Yajl::Projector.new(stream) + expect { + projector.project({"name" => nil}) + }.to raise_error(capture_exception_for(bad_json).class) + end + + it "should behave the same way as the regular parser on bad tokens like colon" do + bad_json = '{"name": "keith", "age":: 27}' + stream = StringIO.new(bad_json) + projector = Yajl::Projector.new(stream) + expect { + projector.project({"name" => nil}) + }.to raise_error(capture_exception_for(bad_json).class) + end + + it "should behave the same way as the regular parser on not enough json" do + bad_json = '{"name": "keith", "age":' + stream = StringIO.new(bad_json) + projector = Yajl::Projector.new(stream) + expect { + projector.project({"name" => nil}) + }.to raise_error(capture_exception_for(bad_json).class) + end + + def capture_exception_for(bad_json) + Yajl::Parser.new.parse(bad_json) + rescue Exception => e + e + end + def project(schema, over: "", json: nil, stream: nil) if stream.nil? if json.nil?