mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-22 19:08:00 +01:00
Add some more tests for valid email address formats
This commit is contained in:
parent
a376587680
commit
533b54a6b7
2 changed files with 97 additions and 0 deletions
|
@ -82,6 +82,12 @@ public final class UserId implements CharSequence {
|
|||
* </ul>
|
||||
* In these cases, {@link #parse(String)} will detect email addresses, names and comments and expose those
|
||||
* via the respective getters.
|
||||
* This method does not support parsing mail addresses of the following formats:
|
||||
* <ul>
|
||||
* <li>Local domains without TLDs (<pre>user@localdomain1</pre>)</li>
|
||||
* <li><pre>" "@example.org</pre> (spaces between the quotes)</li>
|
||||
* <li><pre>"very.(),:;<>[]\".VERY.\"very@\\ \"very\".unusual"@strange.example.com</pre></li>
|
||||
* </ul>
|
||||
*
|
||||
* @see <a href="https://www.rfc-editor.org/rfc/rfc5322#page-16">RFC5322 §3.4. Address Specification</a>
|
||||
* @param string user-id
|
||||
|
|
|
@ -441,4 +441,95 @@ public class UserIdTest {
|
|||
assertEquals("संपर्क@डाटामेल.भारत", samparka.getEmail());
|
||||
assertEquals("संपर्क", samparka.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMailWithPlus() {
|
||||
UserId id = UserId.parse("disposable.style.email.with+symbol@example.com");
|
||||
assertEquals("disposable.style.email.with+symbol@example.com", id.getEmail());
|
||||
|
||||
id = UserId.parse("Disposable Mail <disposable.style.email.with+symbol@example.com>");
|
||||
assertEquals("disposable.style.email.with+symbol@example.com", id.getEmail());
|
||||
assertEquals("Disposable Mail", id.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMailWithHyphen() {
|
||||
UserId id = UserId.parse("other.email-with-hyphen@example.com");
|
||||
assertEquals("other.email-with-hyphen@example.com", id.getEmail());
|
||||
|
||||
id = UserId.parse("Other Email <other.email-with-hyphen@example.com>");
|
||||
assertEquals("other.email-with-hyphen@example.com", id.getEmail());
|
||||
assertEquals("Other Email", id.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMailWithTagAndSorting() {
|
||||
UserId id = UserId.parse("user.name+tag+sorting@example.com");
|
||||
assertEquals("user.name+tag+sorting@example.com", id.getEmail());
|
||||
|
||||
id = UserId.parse("User Name <user.name+tag+sorting@example.com>");
|
||||
assertEquals("user.name+tag+sorting@example.com", id.getEmail());
|
||||
assertEquals("User Name", id.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseMailWithSlash() {
|
||||
UserId id = UserId.parse("test/test@test.com");
|
||||
assertEquals("test/test@test.com", id.getEmail());
|
||||
|
||||
id = UserId.parse("Who uses Slashes <test/test@test.com>");
|
||||
assertEquals("test/test@test.com", id.getEmail());
|
||||
assertEquals("Who uses Slashes", id.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseDoubleDots() {
|
||||
UserId id = UserId.parse("\"john..doe\"@example.org");
|
||||
assertEquals("\"john..doe\"@example.org", id.getEmail());
|
||||
|
||||
id = UserId.parse("John Doe <\"john..doe\"@example.org>");
|
||||
assertEquals("\"john..doe\"@example.org", id.getEmail());
|
||||
assertEquals("John Doe", id.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseBangifiedHostRoute() {
|
||||
UserId id = UserId.parse("mailhost!username@example.org");
|
||||
assertEquals("mailhost!username@example.org", id.getEmail());
|
||||
|
||||
id = UserId.parse("Bangified Host Route <mailhost!username@example.org>");
|
||||
assertEquals("mailhost!username@example.org", id.getEmail());
|
||||
assertEquals("Bangified Host Route", id.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parsePercentRouted() {
|
||||
UserId id = UserId.parse("user%example.com@example.org");
|
||||
assertEquals("user%example.com@example.org", id.getEmail());
|
||||
|
||||
id = UserId.parse("User <user%example.com@example.org>");
|
||||
assertEquals("user%example.com@example.org", id.getEmail());
|
||||
assertEquals("User", id.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseLocalPartEndingWithNonAlphanumericCharacter() {
|
||||
UserId id = UserId.parse("user-@example.org");
|
||||
assertEquals("user-@example.org", id.getEmail());
|
||||
|
||||
id = UserId.parse("User <user-@example.org>");
|
||||
assertEquals("user-@example.org", id.getEmail());
|
||||
assertEquals("User", id.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseDomainIsIpAddress() {
|
||||
UserId id = UserId.parse("postmaster@[123.123.123.123]");
|
||||
assertEquals("postmaster@[123.123.123.123]", id.getEmail());
|
||||
|
||||
id = UserId.parse("Alice (work email) <postmaster@[123.123.123.123]>");
|
||||
assertEquals("postmaster@[123.123.123.123]", id.getEmail());
|
||||
assertEquals("Alice", id.getName());
|
||||
assertEquals("work email", id.getComment());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue