mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-23 11:27:57 +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
|
@Override
|
||||||
public WithAdditionalUserIdOrPassphrase withPrimaryUserId(@Nonnull String userId) {
|
public WithAdditionalUserIdOrPassphrase withPrimaryUserId(@Nonnull String userId) {
|
||||||
KeyRingBuilder.this.userId = userId;
|
KeyRingBuilder.this.userId = userId.trim();
|
||||||
return new WithAdditionalUserIdOrPassphraseImpl();
|
return new WithAdditionalUserIdOrPassphraseImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,10 +215,11 @@ public class KeyRingBuilder implements KeyRingBuilderInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public WithAdditionalUserIdOrPassphrase withAdditionalUserId(@Nonnull String userId) {
|
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.");
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,7 @@ public class GenerateKeyWithAdditionalUserIdTest {
|
||||||
.withPrimaryUserId("primary@user.id")
|
.withPrimaryUserId("primary@user.id")
|
||||||
.withAdditionalUserId("additional@user.id")
|
.withAdditionalUserId("additional@user.id")
|
||||||
.withAdditionalUserId("additional2@user.id")
|
.withAdditionalUserId("additional2@user.id")
|
||||||
|
.withAdditionalUserId("\ttrimThis@user.id ")
|
||||||
.withoutPassphrase()
|
.withoutPassphrase()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -50,6 +51,7 @@ public class GenerateKeyWithAdditionalUserIdTest {
|
||||||
assertEquals("primary@user.id", userIds.next());
|
assertEquals("primary@user.id", userIds.next());
|
||||||
assertEquals("additional@user.id", userIds.next());
|
assertEquals("additional@user.id", userIds.next());
|
||||||
assertEquals("additional2@user.id", userIds.next());
|
assertEquals("additional2@user.id", userIds.next());
|
||||||
|
assertEquals("trimThis@user.id", userIds.next());
|
||||||
assertFalse(userIds.hasNext());
|
assertFalse(userIds.hasNext());
|
||||||
|
|
||||||
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
|
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
|
||||||
|
|
Loading…
Reference in a new issue