diff --git a/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java b/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java index 99f3df37..220c5cb7 100644 --- a/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java +++ b/pgpainless-core/src/main/java/org/pgpainless/key/generation/KeyRingBuilder.java @@ -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; } diff --git a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java index a518cecd..6ab82bb0 100644 --- a/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java +++ b/pgpainless-core/src/test/java/org/pgpainless/key/generation/GenerateKeyWithAdditionalUserIdTest.java @@ -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();