mirror of
https://github.com/golang/go
synced 2024-11-22 18:44:54 -07:00
context: handle nil values for valueCtx.String()
Fixes #68356 Change-Id: I57dc089a99f545e29a6759a8db5e28fabb6d1a61 Reviewed-on: https://go-review.googlesource.com/c/go/+/597415 Commit-Queue: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
183a40db6d
commit
70e453b436
@ -739,6 +739,8 @@ func stringify(v any) string {
|
||||
return s.String()
|
||||
case string:
|
||||
return s
|
||||
case nil:
|
||||
return "<nil>"
|
||||
}
|
||||
return reflectlite.TypeOf(v).String()
|
||||
}
|
||||
|
@ -243,6 +243,10 @@ func TestValues(t *testing.T) {
|
||||
c4 := WithValue(c3, k1, nil)
|
||||
check(c4, "c4", "", "c2k2", "c3k3")
|
||||
|
||||
if got, want := fmt.Sprint(c4), `context.Background.WithValue(context_test.key1, c1k1).WithValue(context_test.key2(1), c2k2).WithValue(context_test.key2(3), c3k3).WithValue(context_test.key1, <nil>)`; got != want {
|
||||
t.Errorf("c.String() = %q want %q", got, want)
|
||||
}
|
||||
|
||||
o0 := otherContext{Background()}
|
||||
check(o0, "o0", "", "", "")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user