diff options
author | Jonathan Amsterdam <jba@google.com> | 2023-05-19 07:31:44 -0400 |
---|---|---|
committer | Jonathan Amsterdam <jba@google.com> | 2023-05-22 18:27:16 +0000 |
commit | 2f1e643229d19f40a5f80dc3784daaff83d5cc02 (patch) | |
tree | 99f965fe4ad8778bbe0c8f37554a520479637a7d /src/log | |
parent | bc96901e8959c5eb21d5bca5614eb66481815918 (diff) | |
download | go-2f1e643229d19f40a5f80dc3784daaff83d5cc02.tar.gz go-2f1e643229d19f40a5f80dc3784daaff83d5cc02.zip |
log/slog: fix check for nil prefix
Previously, handleState.prefix was nil if and only if the length of
the prefix was zero. Now, prefix is never nil.
Fix the nil check in the code by also checking if the length is non-zero.
Change-Id: I9f69c0029cb1c73fe6c2919c78fee7d4085bfd85
Reviewed-on: https://go-review.googlesource.com/c/go/+/495977
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src/log')
-rw-r--r-- | src/log/slog/handler.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/log/slog/handler.go b/src/log/slog/handler.go index b10a6bd247..8cd1e563eb 100644 --- a/src/log/slog/handler.go +++ b/src/log/slog/handler.go @@ -469,7 +469,7 @@ func (s *handleState) appendError(err error) { func (s *handleState) appendKey(key string) { s.buf.WriteString(s.sep) - if s.prefix != nil { + if s.prefix != nil && len(*s.prefix) > 0 { // TODO: optimize by avoiding allocation. s.appendString(string(*s.prefix) + key) } else { |