Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behavior of JSON encoding for Exception #23702

Merged
merged 1 commit into from
Apr 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions activesupport/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Fix behavior of JSON encoding for `Exception`.

*namusyaka*

* Make `number_to_phone` format number with regexp pattern.

number_to_phone(18812345678, pattern: /(\d{3})(\d{4})(\d{4})/)
Expand Down
6 changes: 6 additions & 0 deletions activesupport/lib/active_support/core_ext/object/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,9 @@ def as_json(options = nil)
{ :exitstatus => exitstatus, :pid => pid }
end
end

class Exception
def as_json(options = nil)
to_s
end
end
5 changes: 5 additions & 0 deletions activesupport/test/json/encoding_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,11 @@ def test_twz_to_json_when_wrapping_a_date_time
assert_equal '"1999-12-31T19:00:00.000-05:00"', ActiveSupport::JSON.encode(time)
end

def test_exception_to_json
exception = Exception.new("foo")
assert_equal '"foo"', ActiveSupport::JSON.encode(exception)
end

protected

def object_keys(json_object)
Expand Down