diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2015-06-20 22:56:45 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2015-06-20 23:09:29 +0900 |
commit | 206cf5193808b41c45fd287e5134dffa961a88de (patch) | |
tree | bbbbd46867164e168d0bc9657df9ee1afa6b0ac6 | |
parent | 289ec49f469533c89fbca8303dbfd7b1a43d1197 (diff) | |
download | rails-206cf5193808b41c45fd287e5134dffa961a88de.tar.gz rails-206cf5193808b41c45fd287e5134dffa961a88de.tar.bz2 rails-206cf5193808b41c45fd287e5134dffa961a88de.zip |
Fix infinite loop and lookup miss when `SET` type includes other types
This commit fixes the following problems:
* cause infinit type lookup loop when SET includes aliased types
* For example:
when SET('set') includes aliased type `set`,
then aliased `varchar('set')` by type lookup,
but type lookup infinit matching same rule.
* cause type lookup miss when SET includes registered types
* For example:
when SET('time') includes registered type `time`,
then aliased `varchar('time')` by type lookup,
then matching `time` type.
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 00e3d2965b..7e3a705449 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -789,7 +789,6 @@ module ActiveRecord register_integer_type m, %r(^tinyint)i, limit: 1 m.alias_type %r(tinyint\(1\))i, 'boolean' if emulate_booleans - m.alias_type %r(set)i, 'varchar' m.alias_type %r(year)i, 'integer' m.alias_type %r(bit)i, 'binary' @@ -798,6 +797,12 @@ module ActiveRecord .split(',').map{|enum| enum.strip.length - 2}.max MysqlString.new(limit: limit) end + + m.register_type(%r(^set)i) do |sql_type| + limit = sql_type[/^set\((.+)\)/i, 1] + .split(',').map{|set| set.strip.length - 1}.sum - 1 + MysqlString.new(limit: limit) + end end def register_integer_type(mapping, key, options) # :nodoc: |