mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-19 14:57:04 +00:00
envelope: Handle zero-length keys in AddHeader
We don't expect the AddHeader function to be given an empty key; however, if that were to happen, it currently crashes. This patch fixes the bug, while also adding tests for that and other similar cases.
This commit is contained in:
@@ -39,11 +39,13 @@ func DomainIn(addr string, locals *set.String) bool {
|
||||
}
|
||||
|
||||
func AddHeader(data []byte, k, v string) []byte {
|
||||
// If the value contains newlines, indent them properly.
|
||||
if v[len(v)-1] == '\n' {
|
||||
v = v[:len(v)-1]
|
||||
if len(v) > 0 {
|
||||
// If the value contains newlines, indent them properly.
|
||||
if v[len(v)-1] == '\n' {
|
||||
v = v[:len(v)-1]
|
||||
}
|
||||
v = strings.Replace(v, "\n", "\n\t", -1)
|
||||
}
|
||||
v = strings.Replace(v, "\n", "\n\t", -1)
|
||||
|
||||
header := []byte(fmt.Sprintf("%s: %s\n", k, v))
|
||||
return append(header, data...)
|
||||
|
||||
Reference in New Issue
Block a user