Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix handleTOPIC only supporting modern RPL_TOPIC #72

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,19 @@
// handleTOPIC handles incoming TOPIC events and keeps channel tracking info
// updated with the latest channel topic.
func handleTOPIC(c *Client, e Event) {
var name string
var name, topic string
switch len(e.Params) {
case 0:
return
case 1:
case 1: // TOPIC, message format is `TOPIC <channel>`

Check warning on line 230 in builtin.go

View check run for this annotation

Codecov / codecov/patch

builtin.go#L230

Added line #L230 was not covered by tests
name = e.Params[0]
default:
topic = ""

Check warning on line 232 in builtin.go

View check run for this annotation

Codecov / codecov/patch

builtin.go#L232

Added line #L232 was not covered by tests
case 2: // TOPIC, message format is `TOPIC <channel> :<topic>`
name = e.Params[0]
topic = e.Last()
default: // RPL_TOPIC, message format is `332 <client> <channel> :<topic>`
name = e.Params[1]
topic = e.Last()
}

c.state.Lock()
Expand All @@ -240,7 +245,7 @@
return
}

channel.Topic = e.Last()
channel.Topic = topic
c.state.Unlock()
c.state.notify(c, UPDATE_STATE)
}
Expand Down
7 changes: 6 additions & 1 deletion state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ const mockConnStartState = `:dummy.int NOTICE * :*** Looking up your hostname...
:dummy.int 354 nick 1 #channel nick2 other.int nick2 nick2 :realname2
:dummy.int 315 nick #channel :End of /WHO list.
:[email protected] JOIN #channel2 * :realname
:dummy.int 332 nick #channel2 :example topic
:dummy.int 332 nick #channel2 :example init topic
:dummy.int 353 nick = #channel2 :[email protected] @[email protected]
:dummy.int 366 nick #channel2 :End of /NAMES list.
:dummy.int 354 nick 1 #channel2 ~user local.int nick 0 :realname
:dummy.int 354 nick 1 #channel2 nick2 other.int nick2 nick2 :realname2
:dummy.int 315 nick #channel2 :End of /WHO list.
:dummy.int TOPIC #channel2 :example topic
`

const mockConnEndState = `:[email protected] QUIT :example reason
Expand Down Expand Up @@ -190,6 +191,10 @@ func TestState(t *testing.T) {
t.Fatal("User.InChannel() returned false for existing channel")
}

if ch2 := c.LookupChannel("#channel2"); ch2.Topic != "example topic" {
t.Fatalf("Channel.Topic == %q, want \"example topic\"", ch2.Topic)
}

finishStart <- true
})

Expand Down
Loading