mirror of https://github.com/golang/go.git
log/slog: use Infinity instead of Inf
JSON is derived from Javascript, so we should use Javascript-inspired literals instead of ones more common to Go. In Javascript, infinity is declared as Infinity rather than Inf. Change-Id: I6c81353d0c677640f3f11961a37d792408ac03fc Reviewed-on: https://go-review.googlesource.com/c/go/+/478758 Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
ef0dedce87
commit
16544b83f8
|
|
@ -79,7 +79,7 @@ func (h *JSONHandler) WithGroup(name string) Handler {
|
||||||
// Values are formatted as with encoding/json.Marshal, with the following
|
// Values are formatted as with encoding/json.Marshal, with the following
|
||||||
// exceptions:
|
// exceptions:
|
||||||
// - Floating-point NaNs and infinities are formatted as one of the strings
|
// - Floating-point NaNs and infinities are formatted as one of the strings
|
||||||
// "NaN", "+Inf" or "-Inf".
|
// "NaN", "Infinity" or "-Infinity".
|
||||||
// - Levels are formatted as with Level.String.
|
// - Levels are formatted as with Level.String.
|
||||||
// - HTML characters are not escaped.
|
// - HTML characters are not escaped.
|
||||||
//
|
//
|
||||||
|
|
@ -113,9 +113,9 @@ func appendJSONValue(s *handleState, v Value) error {
|
||||||
// json.Marshal fails on special floats, so handle them here.
|
// json.Marshal fails on special floats, so handle them here.
|
||||||
switch {
|
switch {
|
||||||
case math.IsInf(f, 1):
|
case math.IsInf(f, 1):
|
||||||
s.buf.WriteString(`"+Inf"`)
|
s.buf.WriteString(`"Infinity"`)
|
||||||
case math.IsInf(f, -1):
|
case math.IsInf(f, -1):
|
||||||
s.buf.WriteString(`"-Inf"`)
|
s.buf.WriteString(`"-Infinity"`)
|
||||||
case math.IsNaN(f):
|
case math.IsNaN(f):
|
||||||
s.buf.WriteString(`"NaN"`)
|
s.buf.WriteString(`"NaN"`)
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -111,8 +111,8 @@ func TestJSONAppendAttrValueSpecial(t *testing.T) {
|
||||||
want string
|
want string
|
||||||
}{
|
}{
|
||||||
{math.NaN(), `"NaN"`},
|
{math.NaN(), `"NaN"`},
|
||||||
{math.Inf(+1), `"+Inf"`},
|
{math.Inf(+1), `"Infinity"`},
|
||||||
{math.Inf(-1), `"-Inf"`},
|
{math.Inf(-1), `"-Infinity"`},
|
||||||
{LevelWarn, `"WARN"`},
|
{LevelWarn, `"WARN"`},
|
||||||
} {
|
} {
|
||||||
got := jsonValueString(t, AnyValue(test.value))
|
got := jsonValueString(t, AnyValue(test.value))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue