Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text/template: illegal number syntax: "-" #30948

Closed
bep opened this issue Mar 20, 2019 · 2 comments
Closed

text/template: illegal number syntax: "-" #30948

bep opened this issue Mar 20, 2019 · 2 comments
Assignees
Milestone

Comments

@bep
Copy link
Contributor

@bep bep commented Mar 20, 2019

package main

import (
	"log"
	"text/template"
)

func main() {
	_, err := template.New("").Parse(`{{- .Foo  -}}`)
	if err != nil {
		log.Fatal(err)
	}
}

Fails with:

template: :1: illegal number syntax: "-"

https://play.golang.org/p/VC7LYAI34HU

There is an extra space after .Foo, which is an easy "mistake" to make (I just did), and not always obvious to spot, esp. since there is only a line number in the error message.

@mvdan
Copy link
Member

@mvdan mvdan commented Mar 20, 2019

Thanks for the report! I think this is just a bug in the lexer. I think it should be a valid template to parse. After all, {{ .Foo }} is a valid template, and the mention of - and - never specifies that exactly one space is required.

@mvdan mvdan self-assigned this Mar 20, 2019
@mvdan mvdan added this to the Go1.13 milestone Mar 20, 2019
@gopherbot
Copy link

@gopherbot gopherbot commented Mar 20, 2019

Change https://golang.org/cl/168457 mentions this issue: text/template: allow using -}} with many spaces

@ALTree ALTree added the NeedsFix label Mar 21, 2019
@gopherbot gopherbot closed this in e770b5b Mar 24, 2019
@golang golang locked and limited conversation to collaborators Mar 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.