Skip to content

Commit

Permalink
Don't raise an exception when there are more keys than there are name…
Browse files Browse the repository at this point in the history
…d bind variables when sanitizing conditions.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3382 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
Marcel Molina committed Jan 5, 2006
1 parent a5708b4 commit 945dd92
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 23 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Don't raise an exception when there are more keys than there are named bind variables when sanitizing conditions. [Marcel Molina Jr.]

* Multiple enhancements and adjustments to DB2 adaptor. #3377 [contact@maik-schmidt.de]

* Sanitize scoped conditions. [Marcel Molina Jr.]
Expand Down
1 change: 0 additions & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -1140,7 +1140,6 @@ def replace_bind_variables(statement, values)
end

def replace_named_bind_variables(statement, bind_vars)
raise_if_bind_arity_mismatch(statement, statement.scan(/:(\w+)/).uniq.size, bind_vars.size)
statement.gsub(/:(\w+)/) do
match = $1.to_sym
if bind_vars.include?(match)
Expand Down
6 changes: 0 additions & 6 deletions activerecord/test/deprecated_finder_test.rb
Expand Up @@ -74,12 +74,6 @@ def test_named_bind_variables
assert_nil Company.find_first(["name = :name", { :name => "37signals!" }])
assert_nil Company.find_first(["name = :name", { :name => "37signals!' OR 1=1" }])
assert_kind_of Time, Topic.find_first(["id = :id", { :id => 1 }]).written_on
assert_raises(ActiveRecord::PreparedStatementInvalid) {
Company.find_first(["id=:id and name=:name", { :id=>3 }])
}
assert_raises(ActiveRecord::PreparedStatementInvalid) {
Company.find_first(["id=:id", { :id=>3, :name=>"37signals!" }])
}
end

def test_count
Expand Down
16 changes: 0 additions & 16 deletions activerecord/test/finder_test.rb
Expand Up @@ -157,22 +157,6 @@ def test_named_bind_variables
assert_nil Company.find(:first, :conditions => ["name = :name", { :name => "37signals!" }])
assert_nil Company.find(:first, :conditions => ["name = :name", { :name => "37signals!' OR 1=1" }])
assert_kind_of Time, Topic.find(:first, :conditions => ["id = :id", { :id => 1 }]).written_on
assert_raises(ActiveRecord::PreparedStatementInvalid) {
Company.find(:first, :conditions => ["id=:id and name=:name", { :id=>3 }])
}
assert_raises(ActiveRecord::PreparedStatementInvalid) {
Company.find(:first, :conditions => ["id=:id", { :id=>3, :name=>"37signals!" }])
}
end

def test_named_bind_arity
assert_nothing_raised { bind '', {} }
assert_raises(ActiveRecord::PreparedStatementInvalid) { bind '', :a => 1 }
assert_raises(ActiveRecord::PreparedStatementInvalid) { bind ':a', {} } # ' ruby-mode
assert_nothing_raised { bind ':a', :a => 1 } # ' ruby-mode
assert_raises(ActiveRecord::PreparedStatementInvalid) { bind ':a', :a => 1, :b => 2 } # ' ruby-mode
assert_nothing_raised { bind ':a :a', :a => 1 } # ' ruby-mode
assert_raises(ActiveRecord::PreparedStatementInvalid) { bind ':a :a', :a => 1, :b => 2 } # ' ruby-mode
end

def test_bind_enumerable
Expand Down

0 comments on commit 945dd92

Please sign in to comment.