Inconsistent handling of invalid JSON
maxlinc opened this issue · 1 comments
maxlinc commented
We noticed this in
There is a test for consistent error handling:
it 'raises MultiJson::LoadError on invalid JSON' do
expect{MultiJson.load('{"abc"}')}.to raise_error(MultiJson::LoadError)
end
However, the adapters are not consistent in handling nil or empty inputs. The results of these tests vary depending on the adapter:
it 'raises (any) error on empty JSON' do
expect{MultiJson.load('')}.to raise_error(Exception)
end
it 'raises (any) error on nil JSON' do
expect{MultiJson.load(nil)}.to raise_error(Exception)
end
json_gem and json_pure raise errors for both cases
yajl and oj only raise an error for nil
ok_json does not raise an error for either case
Even among implementations that raise errors, some are MultiJson::LoadError, some are TypeError, and some are ArgumentError.
rwz commented
I guess we're to make MultiJson raise LoadError consistently every time things go wrong.
Thanks for reporting it.