Skip to content

Commit

Permalink
Merge pull request #684 from traPtitech/fix/account-url-parse
Browse files Browse the repository at this point in the history
✨ allow x.com (and fix validation)
  • Loading branch information
ras0q authored Jun 18, 2024
2 parents 0ad2c67 + a4a50f7 commit 4556ac6
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions domain/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
"database/sql/driver"
"fmt"
"net/url"
"regexp"
"time"

Expand Down Expand Up @@ -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]+$"),
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 {
Expand Down

0 comments on commit 4556ac6

Please sign in to comment.