Permalink
Browse files

Change quote delimiters for sql interpolation to obviate SyntaxErrors…

…. Closes 2215. [leroen@gmail.com]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2593 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
Marcel Molina
Marcel Molina committed Oct 14, 2005
1 parent f2c7634 commit 6a6df5f1e297a1b93233acbd851f123232ce1acf
Showing with 9 additions and 1 deletion.
  1. +3 −1 activerecord/lib/active_record/base.rb
  2. +6 −0 activerecord/test/base_test.rb
@@ -1501,7 +1501,9 @@ def quote(value, column = nil)
# Interpolate custom sql string in instance context.
# Optional record argument is meant for custom insert_sql.
def interpolate_sql(sql, record = nil)
- instance_eval("%(#{sql})")
+ # Parens in the sql in, e.g., subselects, cause a parse error, so
+ # escape them.
+ instance_eval("%@#{sql.gsub('@', '\@')}@")
end
# Initializes the attributes array with keys matching the columns from the linked table and
@@ -1018,6 +1018,12 @@ def test_clear_association_cache_new_record
assert_equal firm.clients.collect{ |x| x.name }.sort, clients.collect{ |x| x.name }.sort
end
+ def test_interpolate_sql
+ assert_nothing_raised { Category.new.send(:interpolate_sql, 'foo@bar') }
+ assert_nothing_raised { Category.new.send(:interpolate_sql, 'foo bar) baz') }
+ assert_nothing_raised { Category.new.send(:interpolate_sql, 'foo bar} baz') }
+ end
+
private
def assert_readers(model, exceptions)

0 comments on commit 6a6df5f

Please sign in to comment.