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

TemplateDelims can eat an entire range operator #698

Closed
JRaspass opened this issue May 13, 2024 · 1 comment
Closed

TemplateDelims can eat an entire range operator #698

JRaspass opened this issue May 13, 2024 · 1 comment

Comments

@JRaspass
Copy link

package main

import (
	"fmt"

	"github.com/tdewolff/minify/v2"
	"github.com/tdewolff/minify/v2/html"
)

func main() {
	data := `<select>
	{{ range . }}
		<option>{{ . }}
	{{ end }}
	</select>`

	fmt.Println(data)
	fmt.Println("---")

	m := minify.New()
	m.Add("text/html", &html.Minifier{TemplateDelims: html.GoTemplateDelims})

	var err error
	if data, err = m.String("text/html", data); err != nil {
		panic(err)
	}

	fmt.Println(data)
}

https://go.dev/play/p/YkV7UfwvmIk

<select>
	{{ range . }}
		<option>{{ . }}
	{{ end }}
	</select>
<select><option>{{ . }}
	{{ end }}
	</select>

Not all range operators in my templates were eaten but something about the way this one is written really confuses minify, I've tried to golf it down a bit.

@tdewolff
Copy link
Owner

Thanks James, this was due to text being stripped out of <select> elements, should be fixed now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants