]> Cypherpunks repositories - gostls13.git/commit
text/template: don't evaluate '.' as a float64
authorDaniel Martí <mvdan@mvdan.cc>
Tue, 24 Sep 2019 12:11:36 +0000 (13:11 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Wed, 25 Sep 2019 09:22:38 +0000 (09:22 +0000)
commit0f7b4e72a054f974489d8342cdae5a6a7ba7a31b
tree40b54f8ab121c70269e9203ed148771446aeed34
parent95cbcc5c1c5db05e659b769784e57db777c4cd6a
text/template: don't evaluate '.' as a float64

When using a '.' constant literal as a reflect.Value variadic argument,
idealConstant would incorrectly result in a float64. This is because
rune literals can be represented as a float64, and contain a period,
which tricked the logic into thinking the literal must have been a
floating point number.

This also happened with other characters that can be part of a floating
point number, such as 'e' or 'P'.

To fix these edge cases, exit the case sooner if the literal was a rune,
since that should always go to the int case instead.

Finally, add test cases that verify that they behave properly. These
would error before, since eq would receive a mix of int and float64,
which aren't comparable.

Fixes #34483.

Change-Id: Icfcb7803bfa0cf317a1d1adacacad3d69a57eb42
Reviewed-on: https://go-review.googlesource.com/c/go/+/196808
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Tom Payne <tom@airmap.com>
Reviewed-by: Rob Pike <r@golang.org>
src/text/template/exec.go
src/text/template/exec_test.go