Skip to content

Commit

Permalink
Fix frozen string Ruby 3.4 warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
simi committed Feb 2, 2025
1 parent 351587c commit cfccead
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/helpers/dynamic_errors_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def error_messages_for(*params)
end
end.join.html_safe

contents = ''
contents = +''
contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank?
contents << content_tag(:p, message) unless message.blank?
contents << content_tag(:ul, error_messages)
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/rubygems_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ def rubygem_security_events_link(rubygem)
end

def links_to_owners(rubygem)
rubygem.owners.sort_by(&:id).inject("") { |link, owner| link << link_to_user(owner) }.html_safe
rubygem.owners.sort_by(&:id).inject(+"") { |link, owner| link << link_to_user(owner) }.html_safe
end

def links_to_owners_without_mfa(rubygem)
rubygem.owners.without_mfa.sort_by(&:id).inject("") { |link, owner| link << link_to_user(owner) }.html_safe
rubygem.owners.without_mfa.sort_by(&:id).inject(+"") { |link, owner| link << link_to_user(owner) }.html_safe
end

def link_to_user(user)
Expand Down
2 changes: 1 addition & 1 deletion test/functional/api/v1/api_keys_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def self.should_expect_otp_for_update
context "with credentials with invalid encoding" do
setup do
@user = create(:user)
authorize_with("\x12\xff\x12:creds".force_encoding(Encoding::UTF_8))
authorize_with(String.new("\x12\xff\x12:creds", encoding: Encoding::UTF_8))
get :show
end
should_deny_access
Expand Down
8 changes: 4 additions & 4 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -981,20 +981,20 @@ class UserTest < ActiveSupport::TestCase

should "preserve valid characters so that the format error can be returned" do
# UTF-8 "香" character, which is valid UTF-8, but we reject utf-8 in email addresses
assert_equal "香@example.com", User.normalize_email("\u9999@example.com".force_encoding("utf-8"))
assert_equal "香@example.com", User.normalize_email(String.new("\u9999@example.com", encoding: "utf-8"))

# ISO-8859-1 "Å" character (valid in ISO-8859-1)
encoded_email = "myem\xC5[email protected]".force_encoding("ISO-8859-1")
encoded_email = String.new("myem\xC5[email protected]", encoding: "ISO-8859-1")

assert_equal encoded_email, User.normalize_email(encoded_email)
end

should "return an empty string on invalid inputs" do
# bad encoding when sent as ASCII-8BIT
assert_equal "", User.normalize_email("\u9999@example.com".force_encoding("ascii"))
assert_equal "", User.normalize_email(String.new("\u9999@example.com", encoding: "ascii"))

# ISO-8859-1 "Å" character (invalid in UTF-8, which uses \xC385 for this character)
assert_equal "", User.normalize_email("myem\xC5[email protected]".force_encoding("UTF-8"))
assert_equal "", User.normalize_email(String.new("myem\xC5[email protected]", encoding: "UTF-8"))
end

should "return an empty string for nil" do
Expand Down

0 comments on commit cfccead

Please sign in to comment.