From 50730f74819f86a583a82ea8d705903eac4ba13a Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 25 Feb 2020 21:59:40 +0300 Subject: [PATCH] Add more URL cases for Pleroma, Misskey and Friendica (#1702) --- .../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 f3c21ce5..add21063 100644 --- a/app/src/main/java/com/keylesspalace/tusky/BottomSheetActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/BottomSheetActivity.kt @@ -171,9 +171,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 { @@ -190,10 +193,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 +}