diff --git a/core/src/main/java/com/nextcloud/android/common/core/utils/ecosystem/EcosystemManager.kt b/core/src/main/java/com/nextcloud/android/common/core/utils/ecosystem/EcosystemManager.kt index 52012194..635a7176 100644 --- a/core/src/main/java/com/nextcloud/android/common/core/utils/ecosystem/EcosystemManager.kt +++ b/core/src/main/java/com/nextcloud/android/common/core/utils/ecosystem/EcosystemManager.kt @@ -39,7 +39,12 @@ class EcosystemManager( private const val PLAY_STORE_MARKET_LINK = "market://details?id=" private const val EXTRA_KEY_ACCOUNT = "KEY_ACCOUNT" - const val ACCOUNT_NAME_PATTERN_REGEX = "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-z]{2,}" + const val ACCOUNT_NAME_PATTERN_REGEX = + "^[A-Za-z0-9._%+-]+(?:" + + "@(?:[A-Za-z0-9-]+\\.)+[A-Za-z]{2,}(?:@(?:[A-Za-z0-9-]+\\.)+[A-Za-z]{2,})?" + + "|" + + "@(?:\\d{1,3}\\.){2,3}\\d{1,3}(?::\\d{1,5})?" + + ")$" } private val accountNamePattern = Pattern.compile(ACCOUNT_NAME_PATTERN_REGEX) diff --git a/core/src/test/java/com/nextcloud/android/common/core/utils/AccountNamePatternTest.kt b/core/src/test/java/com/nextcloud/android/common/core/utils/AccountNamePatternTest.kt index e725a7f8..56c63f28 100644 --- a/core/src/test/java/com/nextcloud/android/common/core/utils/AccountNamePatternTest.kt +++ b/core/src/test/java/com/nextcloud/android/common/core/utils/AccountNamePatternTest.kt @@ -52,4 +52,11 @@ class AccountNamePatternTest { assertFalse(pattern.matcher("").matches()) assertFalse(pattern.matcher(" ").matches()) } + + @Test + fun `special account name formats`() { + assertTrue(pattern.matcher("abc@cloud.com@example.inst2.cloud.com").matches()) + assertTrue(pattern.matcher("admin@10.0.2.2:55002").matches()) + assertTrue(pattern.matcher("admin@10.0.2.2").matches()) + } }