diff options
author | Matthew Holt <[email protected]> | 2022-09-01 21:15:20 -0600 |
---|---|---|
committer | Matthew Holt <[email protected]> | 2022-09-01 21:15:44 -0600 |
commit | 73d4a8ba02292491fca289b324e89ef8c62fd435 (patch) | |
tree | df0ce2fd72c75b03490c28686402f3f67d9e9eea /modules/caddyhttp/templates | |
parent | 7d5108d132d3bccfd8d83bc3fc2dbc46afde20ae (diff) | |
download | caddy-73d4a8ba02292491fca289b324e89ef8c62fd435.tar.gz caddy-73d4a8ba02292491fca289b324e89ef8c62fd435.zip |
map: Coerce val to string, fix #4987
Also prevent infinite recursion, and enforce placeholder syntax.
Diffstat (limited to 'modules/caddyhttp/templates')
-rw-r--r-- | modules/caddyhttp/templates/tplcontext.go | 17 |
1 files changed, 2 insertions, 15 deletions
diff --git a/modules/caddyhttp/templates/tplcontext.go b/modules/caddyhttp/templates/tplcontext.go index 96a341c8a..f681399c8 100644 --- a/modules/caddyhttp/templates/tplcontext.go +++ b/modules/caddyhttp/templates/tplcontext.go @@ -305,7 +305,7 @@ func (TemplateContext) funcStripHTML(s string) string { // funcMarkdown renders the markdown body as HTML. The resulting // HTML is NOT escaped so that it can be rendered as HTML. func (TemplateContext) funcMarkdown(input any) (string, error) { - inputStr := toString(input) + inputStr := caddy.ToString(input) md := goldmark.New( goldmark.WithExtensions( @@ -341,7 +341,7 @@ func (TemplateContext) funcMarkdown(input any) (string, error) { // and returns the separated key-value pairs and the body/content. input // must be a "stringy" value. func (TemplateContext) funcSplitFrontMatter(input any) (parsedMarkdownDoc, error) { - meta, body, err := extractFrontMatter(toString(input)) + meta, body, err := extractFrontMatter(caddy.ToString(input)) if err != nil { return parsedMarkdownDoc{}, err } @@ -465,19 +465,6 @@ func (h WrappedHeader) Del(field string) string { return "" } -func toString(input any) string { - switch v := input.(type) { - case string: - return v - case fmt.Stringer: - return v.String() - case error: - return v.Error() - default: - return fmt.Sprintf("%v", input) - } -} - var bufPool = sync.Pool{ New: func() any { return new(bytes.Buffer) |