1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-23 03:17:58 +01:00

Trim user-ids

This commit is contained in:
Paul Schaub 2020-10-20 23:23:25 +02:00
parent c06bedd656
commit f21231ad53
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
2 changed files with 6 additions and 3 deletions

View file

@ -201,7 +201,7 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
@Override
public WithAdditionalUserIdOrPassphrase withPrimaryUserId(@Nonnull String userId) {
KeyRingBuilder.this.userId = userId;
KeyRingBuilder.this.userId = userId.trim();
return new WithAdditionalUserIdOrPassphraseImpl();
}
@ -215,10 +215,11 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
@Override
public WithAdditionalUserIdOrPassphrase withAdditionalUserId(@Nonnull String userId) {
if (KeyRingBuilder.this.userId.equals(userId)) {
String trimmed = userId.trim();
if (KeyRingBuilder.this.userId.equals(trimmed)) {
throw new IllegalArgumentException("Additional user-id MUST NOT be equal to primary user-id.");
}
KeyRingBuilder.this.additionalUserIds.add(userId);
KeyRingBuilder.this.additionalUserIds.add(trimmed);
return this;
}

View file

@ -43,6 +43,7 @@ public class GenerateKeyWithAdditionalUserIdTest {
.withPrimaryUserId("primary@user.id")
.withAdditionalUserId("additional@user.id")
.withAdditionalUserId("additional2@user.id")
.withAdditionalUserId("\ttrimThis@user.id ")
.withoutPassphrase()
.build();
@ -50,6 +51,7 @@ public class GenerateKeyWithAdditionalUserIdTest {
assertEquals("primary@user.id", userIds.next());
assertEquals("additional@user.id", userIds.next());
assertEquals("additional2@user.id", userIds.next());
assertEquals("trimThis@user.id", userIds.next());
assertFalse(userIds.hasNext());
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();