Skip to content

Commit

Permalink
Handle ArgumentError in User.normalize_email
Browse files Browse the repository at this point in the history
To stop 500s that are happening due to errors when calling `downcase` in .normalize_email from Rack::Attack
  • Loading branch information
segiddins authored and simi committed May 1, 2023
1 parent a67f265 commit 77e3421
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ def self.ownership_request_notifiable_owners
where(ownerships: { ownership_request_notifier: true })
end

def self.normalize_email(email)
super
rescue ArgumentError => e
Rails.error.report(e, handled: true)
""
end

def name
handle || email
end
Expand Down
10 changes: 10 additions & 0 deletions test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -833,4 +833,14 @@ class UserTest < ActiveSupport::TestCase
end
end
end

context ".normalize_email" do
should "return the normalized email" do
assert_equal "user@example.com", User.normalize_email(:"UsEr@ example . COM")
end

should "return an empty string on invalid inputs" do
assert_equal "", User.normalize_email("\u9999".force_encoding("ascii"))
end
end
end

0 comments on commit 77e3421

Please sign in to comment.