prevent encoding empty topic segments (#90)

* prevent encoding empty topic segments

* tidy
This commit is contained in:
Paul Wells
2024-03-14 21:57:30 -07:00
committed by GitHub
parent 8ae8bd90c4
commit 5c404ca653
+5 -11
View File
@@ -115,9 +115,11 @@ func formatServerChannel(service string, topic []string, queue bool) string {
defer scratch.Put(p)
b := append(*p, "SRV."...)
b = append(b, service...)
if stringSliceLen(topic) > 0 {
b = append(b, '.')
b = appendChannelParts(b, '.', topic...)
for _, t := range topic {
if len(t) != 0 {
b = append(b, '.')
b = appendSanitizedChannelPart(b, t)
}
}
if queue {
b = append(b, ".Q"...)
@@ -125,14 +127,6 @@ func formatServerChannel(service string, topic []string, queue bool) string {
return string(b)
}
func stringSliceLen(s []string) int {
var n int
for i := range s {
n += len(s[i])
}
return n
}
func formatChannel(delim byte, parts ...any) string {
buf := make([]byte, 0, 4*channelPartsLen(parts...)/3)
return string(appendChannelParts(buf, delim, parts...))