1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/cases/coders
Johannes Opper 894facb196 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.
2016-02-22 17:59:51 +01:00
..
json_test.rb Fix bug in JSON deserialization when column default is an empty string 2016-02-22 17:59:51 +01:00
yaml_column_test.rb