aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2019-03-11 00:48:27 +0900
committerGitHub <noreply@github.com>2019-03-11 00:48:27 +0900
commitb75d6ea5d35d61c60f2675ed956c51e71d2b07ad (patch)
treeb3617c7b218c8b52c85fc5378c13c6b73b064d8e /activerecord
parentc87f6841b77e5827ca7bd03a629e2d615fae0d06 (diff)
parent3e6d3e430e53c550e3c282af6f23b803e1652b15 (diff)
downloadrails-b75d6ea5d35d61c60f2675ed956c51e71d2b07ad.tar.gz
rails-b75d6ea5d35d61c60f2675ed956c51e71d2b07ad.tar.bz2
rails-b75d6ea5d35d61c60f2675ed956c51e71d2b07ad.zip
Merge pull request #35449 from pjrebsch/quoting-empty-range
Quote empty ranges like other empty enumerables
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/CHANGELOG.md4
-rw-r--r--activerecord/lib/active_record/sanitization.rb5
-rw-r--r--activerecord/test/cases/sanitize_test.rb13
3 files changed, 20 insertions, 2 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index cff6a3147b..c0ef3cbe7c 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -1,3 +1,7 @@
+* Quote empty ranges like other empty enumerables.
+
+ *Patrick Rebsch*
+
* Add `insert_all`/`insert_all!`/`upsert_all` methods to `ActiveRecord::Persistence`,
allowing bulk inserts akin to the bulk updates provided by `update_all` and
bulk deletes by `delete_all`.
diff --git a/activerecord/lib/active_record/sanitization.rb b/activerecord/lib/active_record/sanitization.rb
index e6197752bc..750766714d 100644
--- a/activerecord/lib/active_record/sanitization.rb
+++ b/activerecord/lib/active_record/sanitization.rb
@@ -165,10 +165,11 @@ module ActiveRecord
def quote_bound_value(value, c = connection)
if value.respond_to?(:map) && !value.acts_like?(:string)
- if value.respond_to?(:empty?) && value.empty?
+ quoted = value.map { |v| c.quote(v) }
+ if quoted.empty?
c.quote(nil)
else
- value.map { |v| c.quote(v) }.join(",")
+ quoted.join(",")
end
else
c.quote(value)
diff --git a/activerecord/test/cases/sanitize_test.rb b/activerecord/test/cases/sanitize_test.rb
index 18b27bd6d1..6c884b4f45 100644
--- a/activerecord/test/cases/sanitize_test.rb
+++ b/activerecord/test/cases/sanitize_test.rb
@@ -148,6 +148,19 @@ class SanitizeTest < ActiveRecord::TestCase
assert_equal "foo in (#{quoted_nil})", bind("foo in (?)", [])
end
+ def test_bind_range
+ quoted_abc = %(#{ActiveRecord::Base.connection.quote('a')},#{ActiveRecord::Base.connection.quote('b')},#{ActiveRecord::Base.connection.quote('c')})
+ assert_equal "0", bind("?", 0..0)
+ assert_equal "1,2,3", bind("?", 1..3)
+ assert_equal quoted_abc, bind("?", "a"..."d")
+ end
+
+ def test_bind_empty_range
+ quoted_nil = ActiveRecord::Base.connection.quote(nil)
+ assert_equal quoted_nil, bind("?", 0...0)
+ assert_equal quoted_nil, bind("?", "a"..."a")
+ end
+
def test_bind_empty_string
quoted_empty = ActiveRecord::Base.connection.quote("")
assert_equal quoted_empty, bind("?", "")