aboutsummaryrefslogtreecommitdiff
path: root/connector/irc
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-17 21:19:28 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-17 21:19:28 +0100
commitf7ee64cdfe599fce4bbc778c189538b26053d543 (patch)
treef933fe12d42a46c84c2515154a962a11dfaa725d /connector/irc
parentad123342f7ed0a0809b51189b59fe9a1ff2848ce (diff)
downloadeasybridge-f7ee64cdfe599fce4bbc778c189538b26053d543.tar.gz
easybridge-f7ee64cdfe599fce4bbc778c189538b26053d543.zip
Fix query/join with invalid IDs (for IRC)
Diffstat (limited to 'connector/irc')
-rw-r--r--connector/irc/irc.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/connector/irc/irc.go b/connector/irc/irc.go
index aa9723f..38aa79d 100644
--- a/connector/irc/irc.go
+++ b/connector/irc/irc.go
@@ -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
}