aboutsummaryrefslogtreecommitdiff
path: root/src/fmt
diff options
context:
space:
mode:
authorMartin Möhrmann <moehrmann@google.com>2020-07-20 07:57:06 +0200
committerMartin Möhrmann <moehrmann@google.com>2020-08-17 04:55:28 +0000
commit99f179f55a66f35dc7861fa411b42ed61bd0df31 (patch)
tree9d514d3baf46254fa83ec1ae139baeda4dea37fe /src/fmt
parent51ac0f0f4cb432204dee3d434335fd1e61ca8446 (diff)
downloadgo-99f179f55a66f35dc7861fa411b42ed61bd0df31.tar.gz
go-99f179f55a66f35dc7861fa411b42ed61bd0df31.zip
fmt: avoid badverb formatting for %q when used with integers
Instead of returning a bad verb error format for runes above utf8.Maxrune return a quoted utf8.RuneError rune (\ufffd). This makes the behaviour consistent with the "c" verb and aligns behaviour to not return bad verb error format when a verb is applied to the correct argument type. Fixes #14569 Change-Id: I679485f6bb90ebe408423ab68af16cce38816cd0 Reviewed-on: https://go-review.googlesource.com/c/go/+/248759 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/fmt')
-rw-r--r--src/fmt/fmt_test.go8
-rw-r--r--src/fmt/print.go6
2 files changed, 5 insertions, 9 deletions
diff --git a/src/fmt/fmt_test.go b/src/fmt/fmt_test.go
index 6004061020..87fb323809 100644
--- a/src/fmt/fmt_test.go
+++ b/src/fmt/fmt_test.go
@@ -290,11 +290,11 @@ var fmtTests = []struct {
{"%q", '\U00000e00', `'\u0e00'`},
{"%q", '\U0010ffff', `'\U0010ffff'`},
// Runes that are not valid.
- {"%q", int32(-1), "%!q(int32=-1)"},
+ {"%q", int32(-1), `'�'`},
{"%q", 0xDC80, `'�'`},
- {"%q", rune(0x110000), "%!q(int32=1114112)"},
- {"%q", int64(0xFFFFFFFFF), "%!q(int64=68719476735)"},
- {"%q", uint64(0xFFFFFFFFF), "%!q(uint64=68719476735)"},
+ {"%q", rune(0x110000), `'�'`},
+ {"%q", int64(0xFFFFFFFFF), `'�'`},
+ {"%q", uint64(0xFFFFFFFFF), `'�'`},
// width
{"%5s", "abc", " abc"},
diff --git a/src/fmt/print.go b/src/fmt/print.go
index 595869140a..778b5b0938 100644
--- a/src/fmt/print.go
+++ b/src/fmt/print.go
@@ -388,11 +388,7 @@ func (p *pp) fmtInteger(v uint64, isSigned bool, verb rune) {
case 'c':
p.fmt.fmtC(v)
case 'q':
- if v <= utf8.MaxRune {
- p.fmt.fmtQc(v)
- } else {
- p.badVerb(verb)
- }
+ p.fmt.fmtQc(v)
case 'U':
p.fmt.fmtUnicode(v)
default: