Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
Mirrored from https://github.com/Slazee/caddy.git
Synced Nov 11, 02:15 UTC
templates: use the earliest front matter closing fence (#8259)
Jay Hemnani committed
Oct 20, 2026 at 12:37 UTC
8ba327ef3fd71e352d10cee2587b7e6cf9ca9546
2 files changed
+13
-3
modules/caddyhttp/templates/frontmatter.go
+2
-3
@@ -49,15 +49,14 @@ func extractFrontMatter(input string) (map[string]any, string, error) {
49
return nil, input, nil
50
}
51
52
- // find end of front matter
52
+ // find end of front matter: the closing fence that comes first
53
var fmEndFence string
54
fmEndFenceStart := -1
55
for _, fence := range closingFence {
56
index := strings.Index(input[firstLineEnd:], "\n"+fence)
57
- if index >= 0 {
57
+ if index >= 0 && (fmEndFenceStart < 0 || index < fmEndFenceStart) {
58
fmEndFenceStart = index
59
fmEndFence = fence
60
- break
60
}
61
}
62
if fmEndFenceStart < 0 {
modules/caddyhttp/templates/tplcontext_test.go
+11
@@ -605,6 +605,17 @@ yeah`,
605
expect: `Welcome`,
606
body: "\n### Test\n...\nyeah",
607
},
608
+ {
609
+ // yaml closed with dots, with a '---' rule later in the body
610
+ input: `---
611
+title: Welcome
612
+...
613
+### Test
614
+---
615
+yeah`,
616
+ expect: `Welcome`,
617
+ body: "\n### Test\n---\nyeah",
618
+ },
619
{
620
// toml
621
input: `+++