Skip to content

Commit 77f7b8c

Browse files
Merge pull request rails#49837 from jonathanhefner/string-xcase_first-non-frozen-empty-string
Ensure `{down,up}case_first` returns non-frozen string
2 parents ed2839d + bb17d78 commit 77f7b8c

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

activesupport/lib/active_support/inflector/methods.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def humanize(lower_case_and_underscored_word, capitalize: true, keep_id_suffix:
164164
# upcase_first('w') # => "W"
165165
# upcase_first('') # => ""
166166
def upcase_first(string)
167-
string.length > 0 ? string[0].upcase.concat(string[1..-1]) : ""
167+
string.length > 0 ? string[0].upcase.concat(string[1..-1]) : +""
168168
end
169169

170170
# Converts the first character in the string to lowercase.
@@ -173,7 +173,7 @@ def upcase_first(string)
173173
# downcase_first('I') # => "i"
174174
# downcase_first('') # => ""
175175
def downcase_first(string)
176-
string.length > 0 ? string[0].downcase.concat(string[1..-1]) : ""
176+
string.length > 0 ? string[0].downcase.concat(string[1..-1]) : +""
177177
end
178178

179179
# Capitalizes all the words and replaces some characters in the string to

activesupport/test/core_ext/string_ext_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ def test_downcase_first_with_one_char
100100

101101
def test_downcase_first_with_empty_string
102102
assert_equal "", "".downcase_first
103+
assert_not_predicate "".downcase_first, :frozen?
103104
end
104105

105106
def test_upcase_first
@@ -112,6 +113,7 @@ def test_upcase_first_with_one_char
112113

113114
def test_upcase_first_with_empty_string
114115
assert_equal "", "".upcase_first
116+
assert_not_predicate "".upcase_first, :frozen?
115117
end
116118

117119
def test_camelize

0 commit comments

Comments
 (0)