diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2016-06-16 06:14:12 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2016-07-27 00:44:16 +0900 |
commit | a3a6d74c7774fc9f5df4f171bf6e7926c77fbe64 (patch) | |
tree | 3572af614ed5082dad2081ecab3d5f05b4f4e353 /activerecord/lib | |
parent | 245c64d428279122c5ae2ddfdc4d420a87a88f9a (diff) | |
download | rails-a3a6d74c7774fc9f5df4f171bf6e7926c77fbe64.tar.gz rails-a3a6d74c7774fc9f5df4f171bf6e7926c77fbe64.tar.bz2 rails-a3a6d74c7774fc9f5df4f171bf6e7926c77fbe64.zip |
Quoting booleans should return a frozen string
If reuse `QUOTED_TRUE` and `QUOTED_FALSE` without frozen, causing the
following issue.
```
Loading development environment (Rails 5.1.0.alpha)
irb(main):001:0> ActiveRecord::Base.connection.quote(true) << ' foo'
=> "1 foo"
irb(main):002:0> ActiveRecord::Base.connection.quote(true) << ' foo'
=> "1 foo foo"
irb(main):003:0> type = ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlString.new
=> #<ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::MysqlString:0x007fd40c15e018 @precision=nil, @scale=nil, @limit=nil>
irb(main):004:0> type.serialize(true) << ' bar'
=> "1 foo foo bar"
irb(main):005:0> type.cast(true) << ' bar'
=> "1 foo foo bar bar"
```
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/quoting.rb | 8 | ||||
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/mysql/quoting.rb | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb index 860ef17dca..45c7922277 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb @@ -112,19 +112,19 @@ module ActiveRecord end def quoted_true - "'t'" + "'t'".freeze end def unquoted_true - 't' + 't'.freeze end def quoted_false - "'f'" + "'f'".freeze end def unquoted_false - 'f' + 'f'.freeze end # Quote date/time values for use in SQL input. Includes microseconds diff --git a/activerecord/lib/active_record/connection_adapters/mysql/quoting.rb b/activerecord/lib/active_record/connection_adapters/mysql/quoting.rb index fbab654112..5b59e39d9f 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql/quoting.rb @@ -2,7 +2,7 @@ module ActiveRecord module ConnectionAdapters module MySQL module Quoting # :nodoc: - QUOTED_TRUE, QUOTED_FALSE = '1', '0' + QUOTED_TRUE, QUOTED_FALSE = '1'.freeze, '0'.freeze def quote_column_name(name) @quoted_column_names[name] ||= "`#{super.gsub('`', '``')}`" |