Add more URL cases for Pleroma, Misskey and Friendica (#1702)

This commit is contained in:
Alibek Omarov 2020-02-25 21:59:40 +03:00 committed by GitHub
parent 710b9f08c1
commit 50730f7481
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 8 deletions

View file

@ -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 {

View file

@ -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)
)
}
}