Browse Source

event_packet: Fixed bug caused by the second trailing delimiter in a message like `((Remove :01 goofs!*))`

master
Gisle Aune 6 years ago
parent
commit
7233516f87
  1. 33
      client_test.go
  2. 5
      event_packet.go

33
client_test.go

@ -299,3 +299,36 @@ func TestClient(t *testing.T) {
t.Logf("Log[%d] = %#+v", i, logLine) t.Logf("Log[%d] = %#+v", i, logLine)
} }
} }
// TestParenthesesBug tests that the bugfix causing `((Remove :01 goofs!*))` to be parsed as an empty message. It was
// initially thought to be caused by the parentheses (like a hidden m_roleplay NPC attribution removal), hence the name
// for this function.
func TestParenthesesBug(t *testing.T) {
gotMessage := true
client := irc.New(context.Background(), irc.Config{
Nick: "Stuff",
})
irc.Handle(func(event *irc.Event, client *irc.Client) {
if event.Name() == "packet.privmsg" || event.Nick == "Dante" {
gotMessage = true
if event.Text != "((Remove :01 goofs!*))" {
t.Errorf("Expected: %#+v", "((Remove :01 goofs!*))")
t.Errorf("Result: %#+v", event.Text)
}
}
})
packet, err := irc.ParsePacket("@example/tag=32; :Dante!TheBeans@captain.purple.beans PRIVMSG Stuff :((Remove :01 goofs!*))")
if err != nil {
t.Error("Parse", err)
}
client.EmitSync(context.Background(), packet)
if !gotMessage {
t.Error("Message was not received")
}
}

5
event_packet.go

@ -2,6 +2,7 @@ package irc
import ( import (
"errors" "errors"
"fmt"
"strings" "strings"
"time" "time"
) )
@ -63,7 +64,7 @@ func ParsePacket(line string) (Event, error) {
} }
// Parse body // Parse body
split := strings.Split(line, " :")
split := strings.SplitN(line, " :", 2)
tokens := strings.Split(split[0], " ") tokens := strings.Split(split[0], " ")
if len(split) == 2 { if len(split) == 2 {
@ -73,6 +74,8 @@ func ParsePacket(line string) (Event, error) {
event.verb = tokens[0] event.verb = tokens[0]
event.Args = tokens[1:] event.Args = tokens[1:]
fmt.Printf("%#+v\n", split)
// Parse CTCP // Parse CTCP
if (event.verb == "PRIVMSG" || event.verb == "NOTICE") && strings.HasPrefix(event.Text, "\x01") { if (event.verb == "PRIVMSG" || event.verb == "NOTICE") && strings.HasPrefix(event.Text, "\x01") {
verbtext := strings.SplitN(strings.Replace(event.Text, "\x01", "", 2), " ", 2) verbtext := strings.SplitN(strings.Replace(event.Text, "\x01", "", 2), " ", 2)

Loading…
Cancel
Save