Fix query/join with invalid IDs (for IRC)
This commit is contained in:
parent
ad123342f7
commit
f7ee64cdfe
2 changed files with 19 additions and 8 deletions
|
@ -230,7 +230,12 @@ func handleSystemMessage(mxid string, msg string) {
|
|||
}
|
||||
if account != nil {
|
||||
quser := connector.UserID(cmd[2])
|
||||
account.Conn.Invite(quser, connector.RoomID(""))
|
||||
err := account.Conn.Invite(quser, connector.RoomID(""))
|
||||
if err != nil {
|
||||
ezbrSystemSendf(mxid, "%s", err)
|
||||
return
|
||||
}
|
||||
|
||||
quser_mxid, err := dbGetMxUser(account.Protocol, quser)
|
||||
if err != nil {
|
||||
ezbrSystemSendf(mxid, "%s", err)
|
||||
|
|
|
@ -102,7 +102,10 @@ func (irc *IRC) User() UserID {
|
|||
|
||||
func (irc *IRC) checkRoomId(id RoomID) (string, error) {
|
||||
x := strings.Split(string(id), "@")
|
||||
if x[0][0] != '#' || (len(x) == 2 && x[1] != irc.server) {
|
||||
if len(x) == 1 {
|
||||
return "", fmt.Errorf("Please write whole room ID with server: %s@%s", id, irc.server)
|
||||
}
|
||||
if x[0][0] != '#' || len(x) != 2 || x[1] != irc.server {
|
||||
return "", fmt.Errorf("Invalid room ID: %s", id)
|
||||
}
|
||||
return x[0], nil
|
||||
|
@ -110,7 +113,10 @@ func (irc *IRC) checkRoomId(id RoomID) (string, error) {
|
|||
|
||||
func (irc *IRC) checkUserId(id UserID) (string, error) {
|
||||
x := strings.Split(string(id), "@")
|
||||
if x[0][0] == '#' || (len(x) == 2 && x[1] != irc.server) {
|
||||
if len(x) == 1 {
|
||||
return "", fmt.Errorf("Please write whole user ID with server: %s@%s", id, irc.server)
|
||||
}
|
||||
if x[0][0] == '#' || len(x) != 2 || x[1] != irc.server {
|
||||
return "", fmt.Errorf("Invalid user ID: %s", id)
|
||||
}
|
||||
return x[0], nil
|
||||
|
@ -149,6 +155,11 @@ func (irc *IRC) Join(roomId RoomID) error {
|
|||
}
|
||||
|
||||
func (irc *IRC) Invite(userId UserID, roomId RoomID) error {
|
||||
who, err := irc.checkUserId(userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if roomId == "" {
|
||||
return nil
|
||||
}
|
||||
|
@ -158,11 +169,6 @@ func (irc *IRC) Invite(userId UserID, roomId RoomID) error {
|
|||
return err
|
||||
}
|
||||
|
||||
who, err := irc.checkUserId(userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
irc.conn.Cmd.Invite(ch, who)
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue