format: fix crash when emitting empty messages in text format

This commit is contained in:
Serge Bazanski 2020-04-23 21:44:15 +02:00
parent 36f9e53dfd
commit b8b0a5b5c3
1 changed files with 1 additions and 1 deletions

View File

@ -179,7 +179,7 @@ func (tf *textFormatter) format(m proto.Message) (string, error) {
// no trailing newline needed // no trailing newline needed
str := buf.String() str := buf.String()
if str[len(str)-1] == '\n' { if len(str) > 0 && str[len(str)-1] == '\n' {
str = str[:len(str)-1] str = str[:len(str)-1]
} }