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..a134a03f 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,11 @@ 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}\\.){3}\\d{1,3})" + + "(?::\\d{1,5})?" + + "(?:/[^\\s?#]*)?$" } 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..1950d2a9 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,12 @@ 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()) + assertTrue(pattern.matcher("test@example.tld@cloud.example.tld:443/subfolder/deep").matches()) + } }