lrstanley / girc

:bomb: girc is a flexible IRC library for Go :ok_hand:
https://pkg.go.dev/github.com/lrstanley/girc
MIT License
137 stars 13 forks source link

event: Fix serialization of messages with colon but no space #47

Closed nmeum closed 3 years ago

nmeum commented 3 years ago

For messages that contain either a colon or a space character, a messagePrefix needs to be added to the serialized messages. Previously, a message prefix was only added for messages containing a space character. This causes messages which only contain a colon, but not a space to be serialized incorrectly.

For example, prior to this commit a command like PRIVMSG #foo ::), which should send the message :) to the channel #foo, was serialized as PRIVMSG #foo :) which only causes a ) character to be sent to the channel #foo.

lrstanley commented 3 years ago

Originally thought this would work as is, but upon further digging, messagePrefix should only be added if the param contains a space, or begins with :. If the parameter contains a colon, that doesn't necessarily indicate there should be a prefix. As far as the :: scenario, I've adjusted the tests to include this scenario, and I added the specific : prefix check, that should cover these cases.

https://github.com/lrstanley/girc/blob/771323f1624badf1557877055c99557d27d54093/event_test.go#L87-L91

Let me know if this doesn't work.