Skip to content

TemplateDelims can eat an entire range operator #698

@JRaspass

Description

@JRaspass
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions