aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/coders
diff options
context:
space:
mode:
authorJohannes Opper <johannes.opper@gmail.com>2016-02-22 17:36:08 +0100
committerJohannes Opper <johannes.opper@gmail.com>2016-02-22 17:59:51 +0100
commit894facb1967c9f394be92ec699e4eafddc2aea52 (patch)
tree55fddad68c50a6e15e16ffb21702003e28e0e8ea /activerecord/lib/active_record/coders
parentaa3d4408716a2470f85d8e0443cbc7a4ce1ff53d (diff)
downloadrails-894facb1967c9f394be92ec699e4eafddc2aea52.tar.gz
rails-894facb1967c9f394be92ec699e4eafddc2aea52.tar.bz2
rails-894facb1967c9f394be92ec699e4eafddc2aea52.zip
Fix bug in JSON deserialization when column default is an empty string
When `ActiveRecord::Coders::JSON` serialization is used and the default of the column returns `''` it raises the following error: ``` JSON::ParserError: A JSON text must at least contain two octets! ``` If MySQL is running in non-strict mode, it returns an empty string as column default for a text column: ```ruby def extract_default if blob_or_text_column? @default = null || strict ? nil : '' end end ``` Since `''` is invalid JSON, there shouldn't be an attempt to parse it, it should be treated like nil. ActiveRecord::Coders::JSON should behave consistently for all possible non-user-set column default values.
Diffstat (limited to 'activerecord/lib/active_record/coders')
-rw-r--r--activerecord/lib/active_record/coders/json.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/coders/json.rb b/activerecord/lib/active_record/coders/json.rb
index 75d3bfe625..cb185a881e 100644
--- a/activerecord/lib/active_record/coders/json.rb
+++ b/activerecord/lib/active_record/coders/json.rb
@@ -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