strip whitespace when changing e-mail addresses

Fixes #778.
This commit is contained in:
Jonathan Roes 2013-04-27 23:02:23 -04:00
parent 7b8c40028e
commit 057b4768e6
2 changed files with 5 additions and 1 deletions

View File

@ -265,7 +265,7 @@ class UsersController < ApplicationController
requires_parameter(:email)
user = fetch_user_from_params
guardian.ensure_can_edit!(user)
lower_email = Email.downcase(params[:email])
lower_email = Email.downcase(params[:email]).strip
# Raise an error if the email is already in use
if User.where("email = ?", lower_email).exists?

View File

@ -192,6 +192,10 @@ describe UsersController do
it 'raises an error' do
lambda { xhr :put, :change_email, username: user.username, email: other_user.email }.should raise_error(Discourse::InvalidParameters)
end
it 'raises an error if there is whitespace too' do
lambda { xhr :put, :change_email, username: user.username, email: other_user.email + ' ' }.should raise_error(Discourse::InvalidParameters)
end
end
context 'success' do