Skip to content

Commit e6839b4

Browse files
committed
HTNL: fix templates starting with <, fixes #809
1 parent 9b9e4f7 commit e6839b4

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/fsnotify/fsnotify v1.8.0
1010
github.com/matryer/try v0.0.0-20161228173917-9ac251b645a2
1111
github.com/tdewolff/argp v0.0.0-20250209172303-079abae893fb
12-
github.com/tdewolff/parse/v2 v2.7.22
12+
github.com/tdewolff/parse/v2 v2.7.23
1313
github.com/tdewolff/test v1.0.11
1414
)
1515

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3v
2525
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
2626
github.com/tdewolff/argp v0.0.0-20250209172303-079abae893fb h1:Id2aj2q74MC+yHBGQNeTVuQp/gqJd3vZjMmdoVPPfVc=
2727
github.com/tdewolff/argp v0.0.0-20250209172303-079abae893fb/go.mod h1:PKhwRVvnrI2gye5NRF3c4VWbE+3E9mGyRUsNWGcJlDY=
28-
github.com/tdewolff/parse/v2 v2.7.22 h1:ROVbrjtp5RoXi22YSZaOks5DaOcXBJ3PZO5hyyQ9Bbs=
29-
github.com/tdewolff/parse/v2 v2.7.22/go.mod h1:I7TXO37t3aSG9SlPUBefAhgIF8nt7yYUwVGgETIoBcA=
28+
github.com/tdewolff/parse/v2 v2.7.23 h1:sCW2PNTCM1yVldh5YK/8wrpRI9rSbloUZWjAydlN2IA=
29+
github.com/tdewolff/parse/v2 v2.7.23/go.mod h1:I7TXO37t3aSG9SlPUBefAhgIF8nt7yYUwVGgETIoBcA=
3030
github.com/tdewolff/test v1.0.6/go.mod h1:6DAvZliBAAnD7rhVgwaM7DE5/d9NMOAJ09SqYqeK4QE=
3131
github.com/tdewolff/test v1.0.11 h1:FdLbwQVHxqG16SlkGveC0JVyrJN62COWTRyUFzfbtBE=
3232
github.com/tdewolff/test v1.0.11/go.mod h1:XPuWBzvdUzhCuxWO1ojpXsyzsA5bFoS3tO/Q3kFuTG8=

html/html_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ func TestHTMLURL(t *testing.T) {
365365
}
366366
}
367367

368-
func TestHTMLTemplates(t *testing.T) {
368+
func TestHTMLGoTemplates(t *testing.T) {
369369
htmlTests := []struct {
370370
html string
371371
expected string
@@ -404,6 +404,27 @@ func TestHTMLTemplates(t *testing.T) {
404404
}
405405
}
406406

407+
func TestHTMLPHPTemplates(t *testing.T) {
408+
htmlTests := []struct {
409+
html string
410+
expected string
411+
}{
412+
{"\n<div class=\"foo\">\n<?php\necho \"hello\";\n?>\n</div>\n", "<div class=foo><?php\necho \"hello\";\n?></div>"},
413+
}
414+
415+
m := minify.New()
416+
m.AddFunc("text/css", css.Minify)
417+
htmlMinifier := &Minifier{TemplateDelims: PHPTemplateDelims}
418+
for _, tt := range htmlTests {
419+
t.Run(tt.html, func(t *testing.T) {
420+
r := bytes.NewBufferString(tt.html)
421+
w := &bytes.Buffer{}
422+
err := htmlMinifier.Minify(m, w, r, nil)
423+
test.Minify(t, tt.html, err, w.String(), tt.expected)
424+
})
425+
}
426+
}
427+
407428
func TestSpecialTagClosing(t *testing.T) {
408429
m := minify.New()
409430
m.AddFunc("text/html", Minify)

0 commit comments

Comments
 (0)