42wim / matterircd

Connect to your mattermost or slack using your IRC-client of choice.
MIT License
295 stars 60 forks source link

Nicks/usernames with spaces are not sent properly to IRC #184

Closed Aketzu closed 6 years ago

Aketzu commented 6 years ago

If Slack side has a bot user with spaces in name (e.g. "Travis CI") then IRC PRIVMSG's will be incorrect and fail parsing in IRC clients.

For example currently matterircd sends Travis CI!Travis CI@Travis CI PRIVMSG #dev :Build done whereas it should be Travis_CI!Travis_CI@Travis_CI PRIVMSG #dev :Build done

One trivial fix would be to replace (at least) space in sorcix/irc

diff --git a/vendor/github.com/sorcix/irc/message.go b/vendor/github.com/sorcix/irc/message.go
index 088938d..9d34b27 100644
--- a/vendor/github.com/sorcix/irc/message.go
+++ b/vendor/github.com/sorcix/irc/message.go
@@ -123,14 +123,14 @@ func (p *Prefix) IsServer() bool {

 // writeTo is an utility function to write the prefix to the bytes.Buffer in Message.String().
 func (p *Prefix) writeTo(buffer *bytes.Buffer) {
-       buffer.WriteString(p.Name)
+       buffer.WriteString(strings.Replace(p.Name, " ", "_", -1))
        if len(p.User) > 0 {
                buffer.WriteByte(prefixUser)
-               buffer.WriteString(p.User)
+               buffer.WriteString(strings.Replace(p.User, " ", "_", -1))
        }
        if len(p.Host) > 0 {
                buffer.WriteByte(prefixHost)
-               buffer.WriteString(p.Host)
+               buffer.WriteString(strings.Replace(p.Host, " ", "_", -1))
        }
        return
 }

https://tools.ietf.org/html/rfc2812#section-2.3.1 contains list of allowed characters but at least for me it's enought to convert space into underscore

42wim commented 6 years ago

Thanks for reporting, fixed this another way in master. Please reopen if still an issues