fmt: restore padding for %x on byte slices and strings
Also improve the documentation. A prior fix in this release
changed the properties for empty strings and slices, incorrectly.
Previous behavior is now restored and better documented.
Add lots of tests.
The behavior is that when using a string-like format (%s %q %x %X)
a byte slice is equivalent to a string, and printed as a unit. The padding
applies to the entire object. (The space and sharp flags apply
elementwise.)
Fixes #11422.
Fixes #10430.
Change-Id: I758f0521caf71630437e43990ec6d6c9a92655e3
Reviewed-on: https://go-review.googlesource.com/11600
Reviewed-by: Russ Cox <rsc@golang.org>
diff --git a/src/fmt/format.go b/src/fmt/format.go
index ac9f6d8..517b18f 100644
--- a/src/fmt/format.go
+++ b/src/fmt/format.go
@@ -346,7 +346,7 @@
}
buf = append(buf, digits[c>>4], digits[c&0xF])
}
- f.buf.Write(buf)
+ f.pad(buf)
}
// fmt_sx formats a string as a hexadecimal encoding of its bytes.