Skip to content

Commit d14a5de

Browse files
committed
Remove internal sanitize method
Currently internal `sanitize`/`quote_value` method is only used for `quoted_id`. Simply it is enough to use `connection.quote` public API instead.
1 parent 815b730 commit d14a5de

File tree

2 files changed

+1
-13
lines changed

2 files changed

+1
-13
lines changed

activerecord/lib/active_record/sanitization.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,6 @@ module Sanitization
55
extend ActiveSupport::Concern
66

77
module ClassMethods
8-
# Used to sanitize objects before they're used in an SQL SELECT statement.
9-
# Delegates to {connection.quote}[rdoc-ref:ConnectionAdapters::Quoting#quote].
10-
def sanitize(object) # :nodoc:
11-
connection.quote(object)
12-
end
13-
alias_method :quote_value, :sanitize
14-
158
protected
169

1710
# Accepts an array or string of SQL conditions and sanitizes
@@ -216,7 +209,7 @@ def raise_if_bind_arity_mismatch(statement, expected, provided) # :nodoc:
216209

217210
# TODO: Deprecate this
218211
def quoted_id # :nodoc:
219-
self.class.quote_value(@attributes[self.class.primary_key].value_for_database)
212+
self.class.connection.quote(@attributes[self.class.primary_key].value_for_database)
220213
end
221214
end
222215
end

activerecord/test/cases/finder_test.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -877,11 +877,6 @@ def test_named_bind_variables
877877
assert_kind_of Time, Topic.where(["id = :id", { id: 1 }]).first.written_on
878878
end
879879

880-
def test_string_sanitation
881-
assert_not_equal "'something ' 1=1'", ActiveRecord::Base.sanitize("something ' 1=1")
882-
assert_equal "'something; select table'", ActiveRecord::Base.sanitize("something; select table")
883-
end
884-
885880
def test_count_by_sql
886881
assert_equal(0, Entrant.count_by_sql("SELECT COUNT(*) FROM entrants WHERE id > 3"))
887882
assert_equal(1, Entrant.count_by_sql(["SELECT COUNT(*) FROM entrants WHERE id > ?", 2]))

0 commit comments

Comments
 (0)