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:
parent
c06bedd656
commit
f21231ad53
2 changed files with 6 additions and 3 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue