From 2cb25c7a340b56287bd82093878427eb151d2d2c Mon Sep 17 00:00:00 2001 From: ras0q Date: Tue, 18 Jun 2024 18:08:59 +0900 Subject: [PATCH 1/4] :sparkles: allow x.com (and fix validation) --- domain/user.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/domain/user.go b/domain/user.go index a3c6361a..63465707 100644 --- a/domain/user.go +++ b/domain/user.go @@ -4,6 +4,7 @@ import ( "database/sql" "database/sql/driver" "fmt" + "net/url" "regexp" "time" @@ -121,19 +122,23 @@ func (a AccountType) Value() (driver.Value, error) { } func IsValidAccountURL(accountType AccountType, URL string) bool { + if _, err := url.Parse(URL); err != nil { + return false + } + var urlRegexp = map[AccountType]*regexp.Regexp{ HOMEPAGE: regexp.MustCompile("^https?://.+$"), BLOG: regexp.MustCompile("^https?://.+$"), - TWITTER: regexp.MustCompile("^https://twitter.com/[a-zA-Z0-9_]+$"), - FACEBOOK: regexp.MustCompile("^https://www.facebook.com/[a-zA-Z0-9.]+$"), - PIXIV: regexp.MustCompile("^https://www.pixiv.net/users/[0-9]+"), - GITHUB: regexp.MustCompile("^https://github.com/[a-zA-Z0-9-]+$"), - QIITA: regexp.MustCompile("^https://qiita.com/[a-zA-Z0-9-_]+$"), - ZENN: regexp.MustCompile("^https://zenn.dev/[a-zA-Z0-9.]+$"), - ATCODER: regexp.MustCompile("^https://atcoder.jp/users/[a-zA-Z0-9_]+$"), - SOUNDCLOUD: regexp.MustCompile("^https://soundcloud.com/[a-z0-9-_]+$"), - HACKTHEBOX: regexp.MustCompile("^https://app.hackthebox.com/users/[a-zA-Z0-9]+$"), - CTFTIME: regexp.MustCompile("^https://ctftime.org/user/[0-9]+$"), + TWITTER: regexp.MustCompile("^https://(twitter|x)\\.com/[a-zA-Z0-9_]+$"), + FACEBOOK: regexp.MustCompile("^https://www.facebook\\.com/[a-zA-Z0-9.]+$"), + PIXIV: regexp.MustCompile("^https://www.pixiv\\.net/users/[0-9]+"), + GITHUB: regexp.MustCompile("^https://github\\.com/[a-zA-Z0-9-]+$"), + QIITA: regexp.MustCompile("^https://qiita\\.com/[a-zA-Z0-9-_]+$"), + ZENN: regexp.MustCompile("^https://zenn\\.dev/[a-zA-Z0-9.]+$"), + ATCODER: regexp.MustCompile("^https://atcoder\\.jp/users/[a-zA-Z0-9_]+$"), + SOUNDCLOUD: regexp.MustCompile("^https://soundcloud\\.com/[a-z0-9-_]+$"), + HACKTHEBOX: regexp.MustCompile("^https://app.hackthebox\\.com/users/[a-zA-Z0-9]+$"), + CTFTIME: regexp.MustCompile("^https://ctftime\\.org/user/[0-9]+$"), } if r, ok := urlRegexp[accountType]; ok { From 9994cac776d5775e54a6448be4a409d4c4bdc7e5 Mon Sep 17 00:00:00 2001 From: ras0q Date: Tue, 18 Jun 2024 18:11:53 +0900 Subject: [PATCH 2/4] :art: follow gosimple --- domain/user.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/domain/user.go b/domain/user.go index 63465707..80d7a1bb 100644 --- a/domain/user.go +++ b/domain/user.go @@ -127,18 +127,18 @@ func IsValidAccountURL(accountType AccountType, URL string) bool { } var urlRegexp = map[AccountType]*regexp.Regexp{ - HOMEPAGE: regexp.MustCompile("^https?://.+$"), - BLOG: regexp.MustCompile("^https?://.+$"), - TWITTER: regexp.MustCompile("^https://(twitter|x)\\.com/[a-zA-Z0-9_]+$"), - FACEBOOK: regexp.MustCompile("^https://www.facebook\\.com/[a-zA-Z0-9.]+$"), - PIXIV: regexp.MustCompile("^https://www.pixiv\\.net/users/[0-9]+"), - GITHUB: regexp.MustCompile("^https://github\\.com/[a-zA-Z0-9-]+$"), - QIITA: regexp.MustCompile("^https://qiita\\.com/[a-zA-Z0-9-_]+$"), - ZENN: regexp.MustCompile("^https://zenn\\.dev/[a-zA-Z0-9.]+$"), - ATCODER: regexp.MustCompile("^https://atcoder\\.jp/users/[a-zA-Z0-9_]+$"), - SOUNDCLOUD: regexp.MustCompile("^https://soundcloud\\.com/[a-z0-9-_]+$"), - HACKTHEBOX: regexp.MustCompile("^https://app.hackthebox\\.com/users/[a-zA-Z0-9]+$"), - CTFTIME: regexp.MustCompile("^https://ctftime\\.org/user/[0-9]+$"), + HOMEPAGE: regexp.MustCompile(`^https?://.+$`), + BLOG: regexp.MustCompile(`^https?://.+$`), + TWITTER: regexp.MustCompile(`^https://(twitter|x)\.com/[a-zA-Z0-9_]+$`), + FACEBOOK: regexp.MustCompile(`^https://www.facebook\.com/[a-zA-Z0-9.]+$`), + PIXIV: regexp.MustCompile(`^https://www.pixiv\.net/users/[0-9]+`), + GITHUB: regexp.MustCompile(`^https://github\.com/[a-zA-Z0-9-]+$`), + QIITA: regexp.MustCompile(`^https://qiita\.com/[a-zA-Z0-9-_]+$`), + ZENN: regexp.MustCompile(`^https://zenn\.dev/[a-zA-Z0-9.]+$`), + ATCODER: regexp.MustCompile(`^https://atcoder\.jp/users/[a-zA-Z0-9_]+$`), + SOUNDCLOUD: regexp.MustCompile(`^https://soundcloud\.com/[a-z0-9-_]+$`), + HACKTHEBOX: regexp.MustCompile(`^https://app.hackthebox\.com/users/[a-zA-Z0-9]+$`), + CTFTIME: regexp.MustCompile(`^https://ctftime\.org/user/[0-9]+$`), } if r, ok := urlRegexp[accountType]; ok { From 6998444c3e472a6f9d6a000461e44397d9ab85f5 Mon Sep 17 00:00:00 2001 From: ras0q Date: Tue, 18 Jun 2024 18:13:18 +0900 Subject: [PATCH 3/4] :bug: fix subdomain parse --- domain/user.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/domain/user.go b/domain/user.go index 80d7a1bb..a56e13c2 100644 --- a/domain/user.go +++ b/domain/user.go @@ -130,8 +130,8 @@ func IsValidAccountURL(accountType AccountType, URL string) bool { HOMEPAGE: regexp.MustCompile(`^https?://.+$`), BLOG: regexp.MustCompile(`^https?://.+$`), TWITTER: regexp.MustCompile(`^https://(twitter|x)\.com/[a-zA-Z0-9_]+$`), - FACEBOOK: regexp.MustCompile(`^https://www.facebook\.com/[a-zA-Z0-9.]+$`), - PIXIV: regexp.MustCompile(`^https://www.pixiv\.net/users/[0-9]+`), + FACEBOOK: regexp.MustCompile(`^https://www\.facebook\.com/[a-zA-Z0-9.]+$`), + PIXIV: regexp.MustCompile(`^https://www\.pixiv\.net/users/[0-9]+`), GITHUB: regexp.MustCompile(`^https://github\.com/[a-zA-Z0-9-]+$`), QIITA: regexp.MustCompile(`^https://qiita\.com/[a-zA-Z0-9-_]+$`), ZENN: regexp.MustCompile(`^https://zenn\.dev/[a-zA-Z0-9.]+$`), From a4a50f7dadcd89ac92618e08080f99a05eae38c5 Mon Sep 17 00:00:00 2001 From: ras0q Date: Tue, 18 Jun 2024 18:16:05 +0900 Subject: [PATCH 4/4] :bug: fix regexp --- domain/user.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/domain/user.go b/domain/user.go index a56e13c2..be40b6b2 100644 --- a/domain/user.go +++ b/domain/user.go @@ -137,7 +137,7 @@ func IsValidAccountURL(accountType AccountType, URL string) bool { ZENN: regexp.MustCompile(`^https://zenn\.dev/[a-zA-Z0-9.]+$`), ATCODER: regexp.MustCompile(`^https://atcoder\.jp/users/[a-zA-Z0-9_]+$`), SOUNDCLOUD: regexp.MustCompile(`^https://soundcloud\.com/[a-z0-9-_]+$`), - HACKTHEBOX: regexp.MustCompile(`^https://app.hackthebox\.com/users/[a-zA-Z0-9]+$`), + HACKTHEBOX: regexp.MustCompile(`^https://app\.hackthebox\.com/users/[a-zA-Z0-9]+$`), CTFTIME: regexp.MustCompile(`^https://ctftime\.org/user/[0-9]+$`), }