Merge pull request #780 from jroes/fix-778
Strip whitespace when changing e-mail addresses
This commit is contained in:
commit
9e3b70c20e
|
@ -265,7 +265,7 @@ class UsersController < ApplicationController
|
||||||
requires_parameter(:email)
|
requires_parameter(:email)
|
||||||
user = fetch_user_from_params
|
user = fetch_user_from_params
|
||||||
guardian.ensure_can_edit!(user)
|
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
|
# Raise an error if the email is already in use
|
||||||
if User.where("email = ?", lower_email).exists?
|
if User.where("email = ?", lower_email).exists?
|
||||||
|
|
|
@ -192,6 +192,10 @@ describe UsersController do
|
||||||
it 'raises an error' do
|
it 'raises an error' do
|
||||||
lambda { xhr :put, :change_email, username: user.username, email: other_user.email }.should raise_error(Discourse::InvalidParameters)
|
lambda { xhr :put, :change_email, username: user.username, email: other_user.email }.should raise_error(Discourse::InvalidParameters)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context 'success' do
|
context 'success' do
|
||||||
|
|
Loading…
Reference in New Issue