Repository: gohugoio/hugo (language: go)

Issue:
Check for alternate comment prefix when looking at lines before block definition
This works;

```
{{/* Foo */}}
{{ define "main" }}
```

but this does not:

```
{{- /* Foo */}}
{{ define "main" }}
```

References:
- <https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/template.go#L91>
- <https://discourse.gohugo.io/t/41742/10>


Discussion / hints:

Fix patch:
diff --git a/tpl/tplimpl/template.go b/tpl/tplimpl/template.go
index 81c898b2f7a..9a9e82a804c 100644
--- a/tpl/tplimpl/template.go
+++ b/tpl/tplimpl/template.go
@@ -91,9 +91,15 @@ func needsBaseTemplate(templ string) bool {
 		if !inComment && strings.HasPrefix(templ[i:], "{{/*") {
 			inComment = true
 			i += 4
+		} else if !inComment && strings.HasPrefix(templ[i:], "{{- /*") {
+			inComment = true
+			i += 6
 		} else if inComment && strings.HasPrefix(templ[i:], "*/}}") {
 			inComment = false
 			i += 4
+		} else if inComment && strings.HasPrefix(templ[i:], "*/ -}}") {
+			inComment = false
+			i += 6
 		} else {
 			r, size := utf8.DecodeRuneInString(templ[i:])
 			if !inComment {


Test patch:
diff --git a/tpl/tplimpl/integration_test.go b/tpl/tplimpl/integration_test.go
index 49722c5c1dd..4107a1faa35 100644
--- a/tpl/tplimpl/integration_test.go
+++ b/tpl/tplimpl/integration_test.go
@@ -115,3 +115,48 @@ counter2: 3
 `)
 
 }
+
+// Issue 10495
+func TestCommentsBeforeBlockDefinition(t *testing.T) {
+	t.Parallel()
+
+	files := `
+-- config.toml --
+baseURL = 'http://example.com/'
+-- content/s1/p1.md --
+---
+title: "S1P1"
+---
+-- content/s2/p1.md --
+---
+title: "S2P1"
+---
+-- content/s3/p1.md --
+---
+title: "S3P1"
+---
+-- layouts/_default/baseof.html --
+{{ block "main" . }}{{ end }}
+-- layouts/s1/single.html --
+{{/* foo */}}
+{{ define "main" }}{{ .Title }}{{ end }}
+-- layouts/s2/single.html --
+{{- /* foo */}}
+{{ define "main" }}{{ .Title }}{{ end }}
+-- layouts/s3/single.html --
+{{- /* foo */ -}}
+{{ define "main" }}{{ .Title }}{{ end }}
+	`
+
+	b := hugolib.NewIntegrationTestBuilder(
+		hugolib.IntegrationTestConfig{
+			T:           t,
+			TxtarString: files,
+		},
+	)
+	b.Build()
+
+	b.AssertFileContent("public/s1/p1/index.html", `S1P1`)
+	b.AssertFileContent("public/s2/p1/index.html", `S2P1`)
+	b.AssertFileContent("public/s3/p1/index.html", `S3P1`)
+}