aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext
diff options
context:
space:
mode:
authorGannon McGibbon <gannon.mcgibbon@gmail.com>2018-06-03 19:42:07 -0400
committerGannon McGibbon <gannon.mcgibbon@gmail.com>2018-09-28 14:29:46 -0400
commitec9a89cb8be037cde2466a5347ea5c4ec648a4c3 (patch)
tree33c8c7403d6cf9a17e24768d2d99d09f48c2dfed /activesupport/lib/active_support/core_ext
parent9fa4342970e2c8ac24bcc595f120ab65e88095a4 (diff)
downloadrails-ec9a89cb8be037cde2466a5347ea5c4ec648a4c3.tar.gz
rails-ec9a89cb8be037cde2466a5347ea5c4ec648a4c3.tar.bz2
rails-ec9a89cb8be037cde2466a5347ea5c4ec648a4c3.zip
Add deprecation warning when String#first and String#last receive negative integers
[Gannon McGibbon + Eric Turner]
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
-rw-r--r--activesupport/lib/active_support/core_ext/string/access.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb
index 58591bbaaf..4ca24028b0 100644
--- a/activesupport/lib/active_support/core_ext/string/access.rb
+++ b/activesupport/lib/active_support/core_ext/string/access.rb
@@ -75,6 +75,10 @@ class String
# str.first(0) # => ""
# str.first(6) # => "hello"
def first(limit = 1)
+ ActiveSupport::Deprecation.warn(
+ "Calling String#first with a negative integer limit " \
+ "will raise an ArgumentError in Rails 6.1."
+ ) if limit < 0
if limit == 0
""
elsif limit >= size
@@ -95,6 +99,10 @@ class String
# str.last(0) # => ""
# str.last(6) # => "hello"
def last(limit = 1)
+ ActiveSupport::Deprecation.warn(
+ "Calling String#last with a negative integer limit " \
+ "will raise an ArgumentError in Rails 6.1."
+ ) if limit < 0
if limit == 0
""
elsif limit >= size