From 0027dc91b05286d4fc3fc50a4802131881efd6e2 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 11 Jul 2011 12:36:10 +1000 Subject: [PATCH] exp/template: simpler parse of char constants. We can avoid the check against empty constants (''), which UnquoteChar doesn't handle well, by leaving on the trailing quote and seeing that's all we have left at the end. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/4657090 --- src/pkg/exp/template/parse.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/pkg/exp/template/parse.go b/src/pkg/exp/template/parse.go index 77d554d3b5..38a415dbd5 100644 --- a/src/pkg/exp/template/parse.go +++ b/src/pkg/exp/template/parse.go @@ -293,15 +293,12 @@ func newNumber(text string, typ itemType) (*numberNode, os.Error) { n := &numberNode{nodeType: nodeNumber, text: text} switch typ { case itemChar: - if len(text) < 3 { - return nil, fmt.Errorf("illegal character constant: %s", text) - } - rune, _, tail, err := strconv.UnquoteChar(text[1:len(text)-1], text[0]) + rune, _, tail, err := strconv.UnquoteChar(text[1:], text[0]) if err != nil { return nil, err } - if len(tail) > 0 { - return nil, fmt.Errorf("extra bytes in character constant: %s", text) + if tail != "'" { + return nil, fmt.Errorf("malformed character constant: %s", text) } n.int64 = int64(rune) n.isInt = true -- 2.50.0