mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #23810 from xijo/fix_json_coder_when_mysql_strict_is_disabled
Fix bug in JSON deserialization when column default is an empty string
This commit is contained in:
commit
aa7ded6a36
3 changed files with 20 additions and 1 deletions
|
@ -1,2 +1,6 @@
|
|||
* Handle JSON deserialization correctly if the column default from database
|
||||
adapter returns `''` instead of `nil`.
|
||||
|
||||
*Johannes Opper*
|
||||
|
||||
Please check [5-0-stable](https://github.com/rails/rails/blob/5-0-stable/activerecord/CHANGELOG.md) for previous changes.
|
||||
|
|
|
@ -6,7 +6,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def self.load(json)
|
||||
ActiveSupport::JSON.decode(json) unless json.nil?
|
||||
ActiveSupport::JSON.decode(json) unless json.blank?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
15
activerecord/test/cases/coders/json_test.rb
Normal file
15
activerecord/test/cases/coders/json_test.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
require "cases/helper"
|
||||
|
||||
module ActiveRecord
|
||||
module Coders
|
||||
class JSONTest < ActiveRecord::TestCase
|
||||
def test_returns_nil_if_empty_string_given
|
||||
assert_nil JSON.load("")
|
||||
end
|
||||
|
||||
def test_returns_nil_if_nil_given
|
||||
assert_nil JSON.load(nil)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue