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
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bep
Copy link
Contributor

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

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

@ALTree ALTree added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 21, 2019
@golang golang locked and limited conversation to collaborators Mar 23, 2020
@rsc rsc unassigned mvdan Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants