Skip to content

Commit 826fc55

Browse files
oriolgualrwz
authored andcommitted
Oj expects indent as a Fixnum.
When using multi_json with Oj, and also the json lib happens to be laoded, there's a case the json lib sets indent as a String (see https://github.com/ruby/ruby/blob/v2_1_0/ext/json/lib/json/common.rb), making Oj crash with ArgumentError: :indent must be a Fixnum.
1 parent 3b62e64 commit 826fc55

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

lib/multi_json/adapters/oj.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def load(string, options={})
1717

1818
def dump(object, options={})
1919
options.merge!(:indent => 2) if options[:pretty]
20+
options[:indent] = options[:indent].to_i if options[:indent]
2021
::Oj.dump(object, options)
2122
end
2223
end

spec/oj_adapter_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,16 @@
77

88
describe MultiJson::Adapters::Oj do
99
it_behaves_like 'an adapter', described_class
10+
11+
describe '.dump' do
12+
describe '#dump_options' do
13+
before{ MultiJson.use :oj }
14+
before{ MultiJson.dump_options = MultiJson.adapter.dump_options = {} }
15+
after{ MultiJson.dump_options = MultiJson.adapter.dump_options = {} }
16+
17+
it 'ensures indent is a Fixnum' do
18+
expect { MultiJson.dump(42, :indent => '')}.not_to raise_error
19+
end
20+
end
21+
end
1022
end

0 commit comments

Comments
 (0)