diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2015-10-29 14:38:42 -0600 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2015-10-29 15:29:06 -0600 |
commit | 6a6dbb4c51fb0c58ba1a810eaa552774167b758a (patch) | |
tree | 7be0178e37465f01685d46d17c1f7d6bae787bf5 | |
parent | 42eb37ab514060c4217ad2dd845d3bf05007db0f (diff) | |
parent | b1737337e6b6218ae966b57e9484ae7d3aaff7e4 (diff) | |
download | rails-6a6dbb4c51fb0c58ba1a810eaa552774167b758a.tar.gz rails-6a6dbb4c51fb0c58ba1a810eaa552774167b758a.tar.bz2 rails-6a6dbb4c51fb0c58ba1a810eaa552774167b758a.zip |
Merge pull request #13008 from ktheory/sanitize_order
Support SQL sanitization in AR::QueryMethods#order
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 7 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 5 |
2 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index f5afc1000d..ad6c7fa2e5 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -1045,6 +1045,13 @@ module ActiveRecord end def preprocess_order_args(order_args) + order_args.map! do |arg| + if arg.is_a?(Array) && arg.first.to_s.include?('?') + klass.send(:sanitize_sql, arg) + else + arg + end + end order_args.flatten! validate_order_args(order_args) diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 7521f0573a..cd23c1b3e1 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -297,6 +297,11 @@ class RelationTest < ActiveRecord::TestCase assert_equal 3, tags.length end + def test_finding_with_sanitized_order + query = Tag.order(["field(id, ?)", [1,3,2]]).to_sql + assert_match(/field\(id, 1,3,2\)/, query) + end + def test_finding_with_order_limit_and_offset entrants = Entrant.order("id ASC").limit(2).offset(1) |