Skip to content

Commit 0756ddb

Browse files
authored
Merge pull request #6731 from stella-entry/fix/strip-email-whitespace
Fix: Trim whitespace from email before processing
2 parents 0c7c012 + 26a3a25 commit 0756ddb

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

app/controllers/users_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def email_params
120120
end
121121

122122
def update_user_email
123-
@user.update({email: email_params[:email]})
123+
@user.update({email: email_params[:email]&.strip})
124124
@user.filter_old_emails!(@user.email)
125125
end
126126

spec/requests/users_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@
258258
expect(ActionMailer::Base.deliveries.last.body.encoded)
259259
.to match("Click here to confirm your email")
260260
end
261+
262+
it "strips whitespace from email" do
263+
patch update_email_users_path(user),
264+
params: {
265+
user: {
266+
current_password: "12345678",
267+
email: " newemail@example.com "
268+
}
269+
}
270+
user.confirm
271+
expect(user.email).to eq("newemail@example.com")
272+
end
261273
end
262274

263275
context "when failure" do

0 commit comments

Comments
 (0)