Skip to content

Commit fc3e679

Browse files
committed
Remove deprecated support to query using commas on LIMIT
1 parent b466486 commit fc3e679

File tree

4 files changed

+9
-37
lines changed

4 files changed

+9
-37
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove deprecated support to query using commas on LIMIT.
2+
3+
*Rafael Mendonça França*
4+
15
* Remove deprecated support to passing a class as a value in a query.
26

37
*Rafael Mendonça França*

activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,17 +334,12 @@ def empty_insert_statement_value
334334
# Sanitizes the given LIMIT parameter in order to prevent SQL injection.
335335
#
336336
# The +limit+ may be anything that can evaluate to a string via #to_s. It
337-
# should look like an integer, or a comma-delimited list of integers, or
338-
# an Arel SQL literal.
337+
# should look like an integer, or an Arel SQL literal.
339338
#
340339
# Returns Integer and Arel::Nodes::SqlLiteral limits as is.
341-
# Returns the sanitized limit parameter, either as an integer, or as a
342-
# string which contains a comma-delimited list of integers.
343340
def sanitize_limit(limit)
344341
if limit.is_a?(Integer) || limit.is_a?(Arel::Nodes::SqlLiteral)
345342
limit
346-
elsif limit.to_s.include?(",")
347-
Arel.sql limit.to_s.split(",").map { |i| Integer(i) }.join(",")
348343
else
349344
Integer(limit)
350345
end

activerecord/lib/active_record/relation/query_methods.rb

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def #{method_name}=(value) # def includes_values=(value)
7676
end
7777

7878
def bound_attributes
79-
if limit_value && !string_containing_comma?(limit_value)
79+
if limit_value
8080
limit_bind = Attribute.with_cast_value(
8181
"LIMIT".freeze,
8282
connection.sanitize_limit(limit_value),
@@ -690,13 +690,6 @@ def limit(value)
690690
end
691691

692692
def limit!(value) # :nodoc:
693-
if string_containing_comma?(value)
694-
# Remove `string_containing_comma?` when removing this deprecation
695-
ActiveSupport::Deprecation.warn(<<-WARNING.squish)
696-
Passing a string to limit in the form "1,2" is deprecated and will be
697-
removed in Rails 5.1. Please call `offset` explicitly instead.
698-
WARNING
699-
end
700693
self.limit_value = value
701694
self
702695
end
@@ -958,13 +951,7 @@ def build_arel
958951

959952
arel.where(where_clause.ast) unless where_clause.empty?
960953
arel.having(having_clause.ast) unless having_clause.empty?
961-
if limit_value
962-
if string_containing_comma?(limit_value)
963-
arel.take(connection.sanitize_limit(limit_value))
964-
else
965-
arel.take(Arel::Nodes::BindParam.new)
966-
end
967-
end
954+
arel.take(Arel::Nodes::BindParam.new) if limit_value
968955
arel.skip(Arel::Nodes::BindParam.new) if offset_value
969956
arel.group(*arel_columns(group_values.uniq.reject(&:blank?))) unless group_values.empty?
970957

@@ -1192,10 +1179,6 @@ def where_clause_factory
11921179
end
11931180
alias having_clause_factory where_clause_factory
11941181

1195-
def string_containing_comma?(value)
1196-
::String === value && value.include?(",")
1197-
end
1198-
11991182
def default_value_for(name)
12001183
case name
12011184
when :create_with

activerecord/test/cases/base_test.rb

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,6 @@ def test_primary_key_with_no_id
107107
assert_nil Edge.primary_key
108108
end
109109

110-
unless current_adapter?(:PostgreSQLAdapter, :OracleAdapter, :SQLServerAdapter, :FbAdapter)
111-
def test_limit_with_comma
112-
assert_deprecated do
113-
assert Topic.limit("1,2").to_a
114-
end
115-
end
116-
end
117-
118110
def test_many_mutations
119111
car = Car.new name: "<3<3<3"
120112
car.engines_count = 0
@@ -144,10 +136,8 @@ def test_limit_should_sanitize_sql_injection_for_limit_without_commas
144136
end
145137

146138
def test_limit_should_sanitize_sql_injection_for_limit_with_commas
147-
assert_deprecated do
148-
assert_raises(ArgumentError) do
149-
Topic.limit("1, 7 procedure help()").to_a
150-
end
139+
assert_raises(ArgumentError) do
140+
Topic.limit("1, 7 procedure help()").to_a
151141
end
152142
end
153143

0 commit comments

Comments
 (0)