3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-22 03:49:27 +01:00

bump irc-go to latest

This commit is contained in:
Shivaram Lingamneni 2021-02-22 22:11:18 -05:00
parent 2681097516
commit a6f3e2c748
5 changed files with 30 additions and 21 deletions

2
go.mod
View File

@ -10,7 +10,7 @@ require (
github.com/go-sql-driver/mysql v1.5.0 github.com/go-sql-driver/mysql v1.5.0
github.com/go-test/deep v1.0.6 // indirect github.com/go-test/deep v1.0.6 // indirect
github.com/gorilla/websocket v1.4.2 github.com/gorilla/websocket v1.4.2
github.com/goshuirc/irc-go v0.0.0-20210222010959-6e139f6c42e9 github.com/goshuirc/irc-go v0.0.0-20210223005429-8d38e43fc6ed
github.com/onsi/ginkgo v1.12.0 // indirect github.com/onsi/ginkgo v1.12.0 // indirect
github.com/onsi/gomega v1.9.0 // indirect github.com/onsi/gomega v1.9.0 // indirect
github.com/oragono/confusables v0.0.0-20201108231250-4ab98ab61fb1 github.com/oragono/confusables v0.0.0-20201108231250-4ab98ab61fb1

2
go.sum
View File

@ -36,6 +36,8 @@ github.com/goshuirc/irc-go v0.0.0-20210215162435-14cd697c0c8c h1:pOTMO5A1nszuxNy
github.com/goshuirc/irc-go v0.0.0-20210215162435-14cd697c0c8c/go.mod h1:q/JhvvKLmif3y9q8MDQM+gRCnjEKnu5ClF298TTXJug= github.com/goshuirc/irc-go v0.0.0-20210215162435-14cd697c0c8c/go.mod h1:q/JhvvKLmif3y9q8MDQM+gRCnjEKnu5ClF298TTXJug=
github.com/goshuirc/irc-go v0.0.0-20210222010959-6e139f6c42e9 h1:A1mSQ0N5Kx8i+aeqeQ0VLbq3swuH0R/JoQcFcR9yUWA= github.com/goshuirc/irc-go v0.0.0-20210222010959-6e139f6c42e9 h1:A1mSQ0N5Kx8i+aeqeQ0VLbq3swuH0R/JoQcFcR9yUWA=
github.com/goshuirc/irc-go v0.0.0-20210222010959-6e139f6c42e9/go.mod h1:q/JhvvKLmif3y9q8MDQM+gRCnjEKnu5ClF298TTXJug= github.com/goshuirc/irc-go v0.0.0-20210222010959-6e139f6c42e9/go.mod h1:q/JhvvKLmif3y9q8MDQM+gRCnjEKnu5ClF298TTXJug=
github.com/goshuirc/irc-go v0.0.0-20210223005429-8d38e43fc6ed h1:cwwqHrmLafgEucSMC9PmFOA671dc4bEZ5z6FsamnBY8=
github.com/goshuirc/irc-go v0.0.0-20210223005429-8d38e43fc6ed/go.mod h1:q/JhvvKLmif3y9q8MDQM+gRCnjEKnu5ClF298TTXJug=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI= github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=

View File

@ -9,7 +9,6 @@ import (
"bytes" "bytes"
"errors" "errors"
"strings" "strings"
"unicode/utf8"
) )
const ( const (
@ -41,8 +40,8 @@ var (
// (the name references 417 ERR_INPUTTOOLONG; we reserve the right to return it // (the name references 417 ERR_INPUTTOOLONG; we reserve the right to return it
// for messages that exceed the non-tag length limit) // for messages that exceed the non-tag length limit)
ErrorLineTooLong = errors.New("Line could not be parsed because a specified length limit was exceeded") ErrorLineTooLong = errors.New("Line could not be parsed because a specified length limit was exceeded")
// ErrorInvalidTagContent indicates that a tag value was invalid // ErrorInvalidTagContent indicates that a tag name or value was invalid
ErrorInvalidTagContent = errors.New("Line could not be parsed because it contained an invalid tag value") ErrorInvalidTagContent = errors.New("Line could not be processed because it contained an invalid tag name or value")
ErrorCommandMissing = errors.New("IRC messages MUST have a command") ErrorCommandMissing = errors.New("IRC messages MUST have a command")
ErrorBadParam = errors.New("Cannot have an empty param, a param with spaces, or a param that starts with ':' before the last parameter") ErrorBadParam = errors.New("Cannot have an empty param, a param with spaces, or a param that starts with ':' before the last parameter")
@ -168,19 +167,12 @@ func trimInitialSpaces(str string) string {
} }
func parseLine(line string, maxTagDataLength int, truncateLen int) (ircmsg IRCMessage, err error) { func parseLine(line string, maxTagDataLength int, truncateLen int) (ircmsg IRCMessage, err error) {
if strings.IndexByte(line, '\x00') != -1 { // remove either \n or \r\n from the end of the line:
err = ErrorLineContainsBadChar line = strings.TrimSuffix(line, "\n")
return line = strings.TrimSuffix(line, "\r")
} // now validate for the 3 forbidden bytes:
if strings.IndexByte(line, '\x00') != -1 || strings.IndexByte(line, '\n') != -1 || strings.IndexByte(line, '\r') != -1 {
// trim to the first appearance of either '\r' or '\n': return ircmsg, ErrorLineContainsBadChar
lineEnd := strings.IndexByte(line, '\r')
newlineIndex := strings.IndexByte(line, '\n')
if newlineIndex != -1 && (lineEnd == -1 || newlineIndex < lineEnd) {
lineEnd = newlineIndex
}
if lineEnd != -1 {
line = line[:lineEnd]
} }
if len(line) < 1 { if len(line) < 1 {
@ -285,8 +277,7 @@ func (ircmsg *IRCMessage) parseTags(tags string) (err error) {
// "Implementations [...] MUST NOT perform any validation that would // "Implementations [...] MUST NOT perform any validation that would
// reject the message if an invalid tag key name is used." // reject the message if an invalid tag key name is used."
if validateTagName(tagName) { if validateTagName(tagName) {
// "Tag values MUST be encoded as UTF8." if !validateTagValue(tagValue) {
if !utf8.ValidString(tagValue) {
return ErrorInvalidTagContent return ErrorInvalidTagContent
} }
ircmsg.SetTag(tagName, UnescapeTagValue(tagValue)) ircmsg.SetTag(tagName, UnescapeTagValue(tagValue))
@ -356,10 +347,14 @@ func (ircmsg *IRCMessage) line(tagLimit, clientOnlyTagDataLimit, serverAddedTagD
// write the tags, computing the budgets for client-only tags and regular tags // write the tags, computing the budgets for client-only tags and regular tags
var lenRegularTags, lenClientOnlyTags, lenTags int var lenRegularTags, lenClientOnlyTags, lenTags int
if 0 < len(ircmsg.tags) || 0 < len(ircmsg.clientOnlyTags) { if 0 < len(ircmsg.tags) || 0 < len(ircmsg.clientOnlyTags) {
var tagError error
buf.WriteByte('@') buf.WriteByte('@')
firstTag := true firstTag := true
writeTags := func(tags map[string]string) { writeTags := func(tags map[string]string) {
for tag, val := range tags { for tag, val := range tags {
if !(validateTagName(tag) && validateTagValue(val)) {
tagError = ErrorInvalidTagContent
}
if !firstTag { if !firstTag {
buf.WriteByte(';') // delimiter buf.WriteByte(';') // delimiter
} }
@ -380,6 +375,9 @@ func (ircmsg *IRCMessage) line(tagLimit, clientOnlyTagDataLimit, serverAddedTagD
lenClientOnlyTags -= 1 lenClientOnlyTags -= 1
} }
buf.WriteByte(' ') buf.WriteByte(' ')
if tagError != nil {
return nil, tagError
}
} }
lenTags = buf.Len() lenTags = buf.Len()

View File

@ -3,7 +3,10 @@
package ircmsg package ircmsg
import "strings" import (
"strings"
"unicode/utf8"
)
var ( var (
// valtoescape replaces real characters with message tag escapes. // valtoescape replaces real characters with message tag escapes.
@ -73,6 +76,7 @@ func UnescapeTagValue(inString string) string {
return buf.String() return buf.String()
} }
// https://ircv3.net/specs/extensions/message-tags.html#rules-for-naming-message-tags
func validateTagName(name string) bool { func validateTagName(name string) bool {
if len(name) == 0 { if len(name) == 0 {
return false return false
@ -92,3 +96,8 @@ func validateTagName(name string) bool {
} }
return true return true
} }
// "Tag values MUST be encoded as UTF8."
func validateTagValue(value string) bool {
return utf8.ValidString(value)
}

2
vendor/modules.txt vendored
View File

@ -21,7 +21,7 @@ github.com/go-sql-driver/mysql
# github.com/gorilla/websocket v1.4.2 # github.com/gorilla/websocket v1.4.2
## explicit ## explicit
github.com/gorilla/websocket github.com/gorilla/websocket
# github.com/goshuirc/irc-go v0.0.0-20210222010959-6e139f6c42e9 # github.com/goshuirc/irc-go v0.0.0-20210223005429-8d38e43fc6ed
## explicit ## explicit
github.com/goshuirc/irc-go/ircfmt github.com/goshuirc/irc-go/ircfmt
github.com/goshuirc/irc-go/ircmsg github.com/goshuirc/irc-go/ircmsg