Skip to content

Commit 6f444f9

Browse files
committed
Merge pull request #217 from jasonrclark/dont_mutate_dump_default_options
Don't mutate JSON.dump_default_options from dump
2 parents 5a43319 + 98780de commit 6f444f9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/json/common.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def dump(obj, anIO = nil, limit = nil)
390390
end
391391
end
392392
opts = JSON.dump_default_options
393-
limit and opts.update(:max_nesting => limit)
393+
opts = opts.merge(:max_nesting => limit) if limit
394394
result = generate(obj, opts)
395395
if anIO
396396
anIO.write result

tests/test_json.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,12 @@ def test_dump
515515
assert_equal too_deep, output.string
516516
end
517517

518+
def test_dump_should_modify_defaults
519+
max_nesting = JSON.dump_default_options[:max_nesting]
520+
JSON.dump([], StringIO.new, 10)
521+
assert_equal max_nesting, JSON.dump_default_options[:max_nesting]
522+
end
523+
518524
def test_big_integers
519525
json1 = JSON([orig = (1 << 31) - 1])
520526
assert_equal orig, JSON[json1][0]

0 commit comments

Comments
 (0)