mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #30953 from rohitpaulk/fix-io-to-json
Fix #to_json for IO objects, fixes #26132
This commit is contained in:
commit
9c5c0596f1
3 changed files with 18 additions and 0 deletions
|
@ -1,3 +1,11 @@
|
|||
* `IO#to_json` now returns the `to_s` representation, rather than
|
||||
attempting to convert to an array. This fixes a bug where `IO#to_json`
|
||||
would raise an `IOError` when called on an unreadable object.
|
||||
|
||||
Fixes #26132.
|
||||
|
||||
*Paul Kuruvilla*
|
||||
|
||||
* Remove deprecated `halt_callback_chains_on_return_false` option.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
|
|
@ -135,6 +135,12 @@ module Enumerable
|
|||
end
|
||||
end
|
||||
|
||||
class IO
|
||||
def as_json(options = nil) #:nodoc:
|
||||
to_s
|
||||
end
|
||||
end
|
||||
|
||||
class Range
|
||||
def as_json(options = nil) #:nodoc:
|
||||
to_s
|
||||
|
|
|
@ -454,6 +454,10 @@ EXPECTED
|
|||
assert_equal '{"number":null}', NaNNumber.new.to_json
|
||||
end
|
||||
|
||||
def test_to_json_works_on_io_objects
|
||||
assert_equal STDOUT.to_s.to_json, STDOUT.to_json
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def object_keys(json_object)
|
||||
|
|
Loading…
Reference in a new issue