diff options
author | Arthur Neves <arthurnn@gmail.com> | 2013-12-19 16:51:28 -0500 |
---|---|---|
committer | Arthur Neves <arthurnn@gmail.com> | 2013-12-19 16:51:28 -0500 |
commit | 4a720a2cdefc1926e0bfa23b8febd71869093c59 (patch) | |
tree | e6635d07544afff9e3fd3353003fbc562d3c6ae4 | |
parent | e4cde5d58cbb09d1843796f96ba86225ff94fe05 (diff) | |
download | rails-4a720a2cdefc1926e0bfa23b8febd71869093c59.tar.gz rails-4a720a2cdefc1926e0bfa23b8febd71869093c59.tar.bz2 rails-4a720a2cdefc1926e0bfa23b8febd71869093c59.zip |
quoting: Check if id is a valid method before using it
Need to check if valud also respond_to :id before calling it, otherwise
things could explode.
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/quoting.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/sqlite3/quoting_test.rb | 7 |
2 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb index 552a22d28a..75501852ed 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/quoting.rb @@ -43,7 +43,9 @@ module ActiveRecord # SQLite does not understand dates, so this method will convert a Date # to a String. def type_cast(value, column) - return value.id if value.respond_to?(:quoted_id) + if value.respond_to?(:quoted_id) && value.respond_to?(:id) + return value.id + end case value when String, ActiveSupport::Multibyte::Chars diff --git a/activerecord/test/cases/adapters/sqlite3/quoting_test.rb b/activerecord/test/cases/adapters/sqlite3/quoting_test.rb index a7b2764fc1..ba89487838 100644 --- a/activerecord/test/cases/adapters/sqlite3/quoting_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/quoting_test.rb @@ -95,6 +95,13 @@ module ActiveRecord end }.new assert_equal 10, @conn.type_cast(quoted_id_obj, nil) + + quoted_id_obj = Class.new { + def quoted_id + "'zomg'" + end + } + assert_raise(TypeError) { @conn.type_cast(quoted_id_obj, nil) } end end end |