Skip to content

Commit 73f706d

Browse files
Merge pull request #899 from nextcloud/fix/accountPatternRegex
Fix ecosystem account switching : add support for additional account formats
2 parents a6fbfad + a4ab93b commit 73f706d

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

core/src/main/java/com/nextcloud/android/common/core/utils/ecosystem/EcosystemManager.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ class EcosystemManager(
3939
private const val PLAY_STORE_MARKET_LINK = "market://details?id="
4040
private const val EXTRA_KEY_ACCOUNT = "KEY_ACCOUNT"
4141

42-
const val ACCOUNT_NAME_PATTERN_REGEX = "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-z]{2,}"
42+
const val ACCOUNT_NAME_PATTERN_REGEX =
43+
"^[A-Za-z0-9._%+-]+(?:@(?:[A-Za-z0-9-]+\\.)+[A-Za-z]{2,})?" +
44+
"@(?:(?:[A-Za-z0-9-]+\\.)+[A-Za-z]{2,}|(?:\\d{1,3}\\.){3}\\d{1,3})" +
45+
"(?::\\d{1,5})?" +
46+
"(?:/[^\\s?#]*)?$"
4347
}
4448

4549
private val accountNamePattern = Pattern.compile(ACCOUNT_NAME_PATTERN_REGEX)

core/src/test/java/com/nextcloud/android/common/core/utils/AccountNamePatternTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,12 @@ class AccountNamePatternTest {
5252
assertFalse(pattern.matcher("").matches())
5353
assertFalse(pattern.matcher(" ").matches())
5454
}
55+
56+
@Test
57+
fun `special account name formats`() {
58+
assertTrue(pattern.matcher("abc@cloud.com@example.inst2.cloud.com").matches())
59+
assertTrue(pattern.matcher("admin@10.0.2.2:55002").matches())
60+
assertTrue(pattern.matcher("admin@10.0.2.2").matches())
61+
assertTrue(pattern.matcher("test@example.tld@cloud.example.tld:443/subfolder/deep").matches())
62+
}
5563
}

0 commit comments

Comments
 (0)