CreateEmail: Trim new email
This removes leading and trailing whitespace from the email. Change-Id: Ia2e70925572a07d7d5ed170a774894f2a5bf4543 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -21,6 +21,7 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.extensions.api.accounts.EmailInput;
|
||||
import com.google.gerrit.extensions.common.EmailInfo;
|
||||
import com.google.gerrit.extensions.restapi.IdString;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -46,6 +47,15 @@ public class EmailIT extends AbstractDaemonTest {
|
||||
assertThat(getEmails()).contains(email);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addEmailWithLeadingAndTrailingWhitespace() throws Exception {
|
||||
String email = "foo.bar3@example.com";
|
||||
assertThat(getEmails()).doesNotContain(email);
|
||||
|
||||
createEmail(IdString.fromDecoded(" " + email + " ").encoded());
|
||||
assertThat(getEmails()).contains(email);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteEmail() throws Exception {
|
||||
String email = "foo.baz@example.com";
|
||||
|
@@ -70,7 +70,7 @@ public class CreateEmail implements RestModifyView<AccountResource, EmailInput>
|
||||
this.accountManager = accountManager;
|
||||
this.registerNewEmailFactory = registerNewEmailFactory;
|
||||
this.putPreferred = putPreferred;
|
||||
this.email = email;
|
||||
this.email = email != null ? email.trim() : null;
|
||||
this.isDevMode = authConfig.getAuthType() == DEVELOPMENT_BECOME_ANY_ACCOUNT;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user