aboutsummaryrefslogtreecommitdiff
path: root/src/text/template/exec.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2019-01-29 23:21:29 -0500
committerRuss Cox <rsc@golang.org>2019-02-26 05:18:38 +0000
commit3cf56e78d812069d2ffb65b5c29a76961b0b0af8 (patch)
tree87030b7ca0a2b40a406a12db80f84d3154b9d5c4 /src/text/template/exec.go
parentf601d412ceae1338999b203c50168af34285c634 (diff)
downloadgo-3cf56e78d812069d2ffb65b5c29a76961b0b0af8.tar.xz
text/template: accept new number syntax
This CL updates text/template's scanner to accept the new number syntaxes: - Hexadecimal floating-point values. - Digit-separating underscores. - Leading 0b and 0o prefixes. See golang.org/design/19308-number-literals for background. For #12711. For #19308. For #28493. For #29008. Change-Id: I68c16ea35c3f506701063781388de72bafee6b8d Reviewed-on: https://go-review.googlesource.com/c/160248 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/text/template/exec.go')
-rw-r--r--src/text/template/exec.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/text/template/exec.go b/src/text/template/exec.go
index c6ce657cf6..d34d248441 100644
--- a/src/text/template/exec.go
+++ b/src/text/template/exec.go
@@ -495,7 +495,7 @@ func (s *state) idealConstant(constant *parse.NumberNode) reflect.Value {
switch {
case constant.IsComplex:
return reflect.ValueOf(constant.Complex128) // incontrovertible.
- case constant.IsFloat && !isHexConstant(constant.Text) && strings.ContainsAny(constant.Text, ".eE"):
+ case constant.IsFloat && !isHexInt(constant.Text) && strings.ContainsAny(constant.Text, ".eEpP"):
return reflect.ValueOf(constant.Float64)
case constant.IsInt:
n := int(constant.Int64)
@@ -509,8 +509,8 @@ 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 isHexInt(s string) bool {
+ return len(s) > 2 && s[0] == '0' && (s[1] == 'x' || s[1] == 'X') && !strings.ContainsAny(s, "pP")
}
func (s *state) evalFieldNode(dot reflect.Value, field *parse.FieldNode, args []parse.Node, final reflect.Value) reflect.Value {