Skip to content
  • Johannes Opper's avatar
    894facb1
    Fix bug in JSON deserialization when column default is an empty string · 894facb1
    Johannes Opper authored
    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.
    894facb1
    Fix bug in JSON deserialization when column default is an empty string
    Johannes Opper authored
    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.
Loading