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

bep opened this issue Mar 20, 2019 · 2 comments

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

bep opened this issue Mar 20, 2019 · 2 comments


Copy link

@bep bep commented Mar 20, 2019

package main

import (

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

Fails with:

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

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.

Copy link

@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
Copy link

@gopherbot gopherbot commented Mar 20, 2019

Change 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.
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.