diff options
| author | Rob Pike <r@golang.org> | 2014-09-03 15:57:03 -0700 |
|---|---|---|
| committer | Rob Pike <r@golang.org> | 2014-09-03 15:57:03 -0700 |
| commit | 55fa7659c990701b3b7fb21e5364585793b9e452 (patch) | |
| tree | 0c6353026ed26f946c29aac8b92305aa0c1a81dc /src/pkg/text/template/exec.go | |
| parent | 5ea69978fd07abdd4bb5ed63dfb38700389493c6 (diff) | |
| download | go-55fa7659c990701b3b7fb21e5364585793b9e452.tar.xz | |
text/template: 0xef is an integer, not a floating-point value.
The discriminator in the execution engine was stupid.
Add a test to the parse package too. The problem wasn't there
but the particular case ('e' in a hex integer) was not covered.
Fixes #8622.
LGTM=ruiu
R=golang-codereviews, ruiu
CC=golang-codereviews
https://golang.org/cl/133530043
Diffstat (limited to 'src/pkg/text/template/exec.go')
| -rw-r--r-- | src/pkg/text/template/exec.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/pkg/text/template/exec.go b/src/pkg/text/template/exec.go index 2f32312645..8e155d478e 100644 --- a/src/pkg/text/template/exec.go +++ b/src/pkg/text/template/exec.go @@ -393,7 +393,7 @@ func (s *state) idealConstant(constant *parse.NumberNode) reflect.Value { switch { case constant.IsComplex: return reflect.ValueOf(constant.Complex128) // incontrovertible. - case constant.IsFloat && strings.IndexAny(constant.Text, ".eE") >= 0: + case constant.IsFloat && !isHexConstant(constant.Text) && strings.IndexAny(constant.Text, ".eE") >= 0: return reflect.ValueOf(constant.Float64) case constant.IsInt: n := int(constant.Int64) @@ -407,6 +407,10 @@ func (s *state) idealConstant(constant *parse.NumberNode) reflect.Value { return zero } +func isHexConstant(s string) bool { + return len(s) > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X') +} + func (s *state) evalFieldNode(dot reflect.Value, field *parse.FieldNode, args []parse.Node, final reflect.Value) reflect.Value { s.at(field) return s.evalFieldChain(dot, dot, field, field.Ident, args, final) |
