Commit cbd2c7a2 authored by Robert Dinu's avatar Robert Dinu Committed by Rob Pike

fmt: fix width for nil values

Apply width when using Printf with nil values.
Fixes #4772.

R=r, adg
CC=golang-dev
https://golang.org/cl/7314114
parent d8682f99
...@@ -178,6 +178,8 @@ var fmttests = []struct { ...@@ -178,6 +178,8 @@ var fmttests = []struct {
{"%.3q", "日本語日本語", `"日本語"`}, {"%.3q", "日本語日本語", `"日本語"`},
{"%.3q", []byte("日本語日本語"), `"日本語"`}, {"%.3q", []byte("日本語日本語"), `"日本語"`},
{"%10.1q", "日本語日本語", ` "日"`}, {"%10.1q", "日本語日本語", ` "日"`},
{"%10v", nil, " <nil>"},
{"%-10v", nil, "<nil> "},
// integers // integers
{"%d", 12345, "12345"}, {"%d", 12345, "12345"},
...@@ -437,6 +439,8 @@ var fmttests = []struct { ...@@ -437,6 +439,8 @@ var fmttests = []struct {
{"%T", renamedComplex128(4 - 3i), "fmt_test.renamedComplex128"}, {"%T", renamedComplex128(4 - 3i), "fmt_test.renamedComplex128"},
{"%T", intVal, "int"}, {"%T", intVal, "int"},
{"%6T", &intVal, " *int"}, {"%6T", &intVal, " *int"},
{"%10T", nil, " <nil>"},
{"%-10T", nil, "<nil> "},
// %p // %p
{"p0=%p", new(int), "p0=0xPTR"}, {"p0=%p", new(int), "p0=0xPTR"},
......
...@@ -729,7 +729,7 @@ func (p *pp) printField(field interface{}, verb rune, plus, goSyntax bool, depth ...@@ -729,7 +729,7 @@ func (p *pp) printField(field interface{}, verb rune, plus, goSyntax bool, depth
if field == nil { if field == nil {
if verb == 'T' || verb == 'v' { if verb == 'T' || verb == 'v' {
p.buf.Write(nilAngleBytes) p.fmt.pad(nilAngleBytes)
} else { } else {
p.badVerb(verb) p.badVerb(verb)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment