PM-19771: Allow forward slashes in emails (#5137)

This commit is contained in:
David Perez
2025-05-06 17:12:48 -05:00
committed by GitHub
parent 5abcc5b1f7
commit 5dd34afe81
2 changed files with 4 additions and 2 deletions

View File

@@ -45,14 +45,14 @@ fun String?.orZeroWidthSpace(): String = this.orNullIfBlank() ?: ZERO_WIDTH_CHAR
*
* This validates that the email is valid by asserting that:
* * The string starts with a string of characters including periods, underscores, percent symbols,
* plus's, minus's, and alphanumeric characters.
* plus's, minus's, forward slash's, and alphanumeric characters.
* * Followed by an '@' symbol.
* * Followed by a string of characters including periods, minus's, and alphanumeric characters.
* * Followed by a period.
* * Followed by at least 2 more alphanumeric characters.
*/
fun String.isValidEmail(): Boolean =
this.matches(regex = "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$".toRegex())
this.matches(regex = "^[A-Za-z0-9._%+-/]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$".toRegex())
/**
* Returns `true` if the given [String] is a non-blank, valid URI and `false` otherwise.

View File

@@ -26,6 +26,8 @@ class StringExtensionsTest {
"test@test.test.com" to true,
"test.test@test.com" to true,
"test.test@test.test.com" to true,
"test/test@test.test.com" to true,
"test.test@test/test.com" to false,
)
invalidEmails.forEach {
assertEquals(it.first.isValidEmail(), it.second)