From ceba88af5c538ff801b07c5d0531db3ccf7bfde2 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Wed, 19 Feb 2020 04:56:21 +0300 Subject: [PATCH] Add MORE cases for Pleroma, Misskey and Friendica --- .../tusky/BottomSheetActivity.kt | 16 +++++++---- .../tusky/BottomSheetActivityTest.kt | 27 ++++++++++++++++--- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/BottomSheetActivity.kt b/app/src/main/java/com/keylesspalace/tusky/BottomSheetActivity.kt index d56d6711..392bf9dd 100644 --- a/app/src/main/java/com/keylesspalace/tusky/BottomSheetActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/BottomSheetActivity.kt @@ -169,9 +169,12 @@ abstract class BottomSheetActivity : BaseActivity() { // https://mastodon.foo.bar/@User // https://mastodon.foo.bar/@User/43456787654678 // https://pleroma.foo.bar/users/User -// https://pleroma.foo.bar/users/43456787654678 -// https://pleroma.foo.bar/notice/43456787654678 +// https://pleroma.foo.bar/users/9qTHT2ANWUdXzENqC0 +// https://pleroma.foo.bar/notice/9sBHWIlwwGZi5QGlHc // https://pleroma.foo.bar/objects/d4643c42-3ae0-4b73-b8b0-c725f5819207 +// https://friendica.foo.bar/profile/user +// https://friendica.foo.bar/display/d4643c42-3ae0-4b73-b8b0-c725f5819207 +// https://misskey.foo.bar/notes/83w6r388br (always lowercase) fun looksLikeMastodonUrl(urlString: String): Boolean { val uri: URI try { @@ -188,10 +191,13 @@ fun looksLikeMastodonUrl(urlString: String): Boolean { val path = uri.path return path.matches("^/@[^/]+$".toRegex()) || - path.matches("^/users/[^/]+$".toRegex()) || path.matches("^/@[^/]+/\\d+$".toRegex()) || - path.matches("^/notice/\\d+$".toRegex()) || - path.matches("^/objects/[-a-f0-9]+$".toRegex()) + path.matches("^/users/\\w+$".toRegex()) || + path.matches("^/notice/[a-zA-Z0-9]+$".toRegex()) || + path.matches("^/objects/[-a-f0-9]+$".toRegex()) || + path.matches("^/notes/[a-z0-9]+$".toRegex()) || + path.matches("^/display/[-a-f0-9]+$".toRegex()) || + path.matches("^/profile/\\w+$".toRegex()) } enum class PostLookupFallbackBehavior { diff --git a/app/src/test/java/com/keylesspalace/tusky/BottomSheetActivityTest.kt b/app/src/test/java/com/keylesspalace/tusky/BottomSheetActivityTest.kt index d3c54f0e..5c92667e 100644 --- a/app/src/test/java/com/keylesspalace/tusky/BottomSheetActivityTest.kt +++ b/app/src/test/java/com/keylesspalace/tusky/BottomSheetActivityTest.kt @@ -119,10 +119,21 @@ class BottomSheetActivityTest { arrayOf("https://mastodon.foo.bar/@user/345667890345678", true), arrayOf("https://mastodon.foo.bar/@user/3", true), arrayOf("https://pleroma.foo.bar/users/meh3223", true), + arrayOf("https://pleroma.foo.bar/users/meh3223_bruh", true), arrayOf("https://pleroma.foo.bar/users/2345", true), arrayOf("https://pleroma.foo.bar/notice/9", true), arrayOf("https://pleroma.foo.bar/notice/9345678", true), + arrayOf("https://pleroma.foo.bar/notice/wat", true), + arrayOf("https://pleroma.foo.bar/notice/9qTHT2ANWUdXzENqC0", true), arrayOf("https://pleroma.foo.bar/objects/abcdef-123-abcd-9876543", true), + arrayOf("https://misskey.foo.bar/notes/mew", true), + arrayOf("https://misskey.foo.bar/notes/1421564653", true), + arrayOf("https://misskey.foo.bar/notes/qwer615985ddf", true), + arrayOf("https://friendica.foo.bar/profile/user", true), + arrayOf("https://friendica.foo.bar/profile/uSeR", true), + arrayOf("https://friendica.foo.bar/profile/user_user", true), + arrayOf("https://friendica.foo.bar/profile/123", true), + arrayOf("https://friendica.foo.bar/display/abcdef-123-abcd-9876543", true), arrayOf("https://google.com/", false), arrayOf("https://mastodon.foo.bar/@User?foo=bar", false), arrayOf("https://mastodon.foo.bar/@User#foo", false), @@ -131,13 +142,23 @@ class BottomSheetActivityTest { arrayOf("https://mastodon.foo.bar/@user/345667890345678/", false), arrayOf("https://mastodon.foo.bar/@user/3abce", false), arrayOf("https://pleroma.foo.bar/users/", false), + arrayOf("https://pleroma.foo.bar/users/meow/", false), + arrayOf("https://pleroma.foo.bar/users/@meow", false), arrayOf("https://pleroma.foo.bar/user/2345", false), - arrayOf("https://pleroma.foo.bar/notice/wat", false), arrayOf("https://pleroma.foo.bar/notices/123456", false), + arrayOf("https://pleroma.foo.bar/notice/@neverhappen/", false), arrayOf("https://pleroma.foo.bar/object/abcdef-123-abcd-9876543", false), arrayOf("https://pleroma.foo.bar/objects/xabcdef-123-abcd-9876543", false), arrayOf("https://pleroma.foo.bar/objects/xabcdef-123-abcd-9876543/", false), - arrayOf("https://pleroma.foo.bar/objects/xabcdef-123-abcd_9876543", false) + arrayOf("https://pleroma.foo.bar/objects/xabcdef-123-abcd_9876543", false), + arrayOf("https://friendica.foo.bar/display/xabcdef-123-abcd-9876543", false), + arrayOf("https://friendica.foo.bar/display/xabcdef-123-abcd-9876543/", false), + arrayOf("https://friendica.foo.bar/display/xabcdef-123-abcd_9876543", false), + arrayOf("https://friendica.foo.bar/profile/@mew", false), + arrayOf("https://friendica.foo.bar/profile/@mew/", false), + arrayOf("https://misskey.foo.bar/notes/@nyan", false), + arrayOf("https://misskey.foo.bar/notes/NYAN123", false), + arrayOf("https://misskey.foo.bar/notes/meow123/", false) ) } } @@ -299,4 +320,4 @@ class BottomSheetActivityTest { this.fallbackBehavior = fallbackBehavior } } -} \ No newline at end of file +}