mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-12-30 07:26:14 -06:00
fix mention extracting when no domain exists (usually when intra-instance mentions)
Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
parent
3dc7644ae6
commit
730366ddf1
3 changed files with 9 additions and 11 deletions
|
|
@ -565,13 +565,10 @@ func ExtractMention(i Mentionable) (*gtsmodel.Mention, error) {
|
|||
}
|
||||
|
||||
// just make sure the mention string is valid so we can handle it properly later on...
|
||||
username, domain, err := util.ExtractMentionParts(mentionString)
|
||||
_, _, err = util.ExtractMentionParts(mentionString)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if username == "" || domain == "" {
|
||||
return nil, errors.New("username or domain was empty")
|
||||
}
|
||||
mention.NameString = mentionString
|
||||
|
||||
// the href prop should be the AP URI of a user we know, eg https://example.org/users/whatever_user
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
mentionName = `^@(\w+)(?:@([a-zA-Z0-9_\-\.:]+)?)$`
|
||||
mentionName = `^@(\w+)(?:@([a-zA-Z0-9_\-\.:]+))?$`
|
||||
// MentionName captures the username and domain part from a mention string
|
||||
// such as @whatever_user@example.org, returning whatever_user and example.org (without the @ symbols)
|
||||
MentionName = regexp.MustCompile(mentionName)
|
||||
|
|
|
|||
|
|
@ -68,13 +68,14 @@ func DeriveEmojisFromText(text string) []string {
|
|||
// If nothing is matched, it will return an error.
|
||||
func ExtractMentionParts(mention string) (username, domain string, err error) {
|
||||
matches := regexes.MentionName.FindStringSubmatch(mention)
|
||||
if matches == nil || len(matches) != 3 {
|
||||
err = fmt.Errorf("could't match mention %s", mention)
|
||||
return
|
||||
switch len(matches) {
|
||||
case 2:
|
||||
return matches[1], "", nil
|
||||
case 3:
|
||||
return matches[1], matches[2], nil
|
||||
default:
|
||||
return "", "", fmt.Errorf("couldn't match mention %s", mention)
|
||||
}
|
||||
username = matches[1]
|
||||
domain = matches[2]
|
||||
return
|
||||
}
|
||||
|
||||
// IsMention returns true if the passed string looks like @whatever@example.org
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue