From 003403ecbccbd3fa53040ee1f0fd5d411a887215 Mon Sep 17 00:00:00 2001 From: Francis Lavoie Date: Mon, 15 Jun 2020 14:38:51 -0400 Subject: templates: Add support for dots to close yaml frontmatter (#3498) * templates: Add support for dots to close yaml frontmatter * templates: Fix regression in body output --- modules/caddyhttp/templates/tplcontext_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'modules/caddyhttp/templates/tplcontext_test.go') diff --git a/modules/caddyhttp/templates/tplcontext_test.go b/modules/caddyhttp/templates/tplcontext_test.go index 4c3da03..f90b851 100644 --- a/modules/caddyhttp/templates/tplcontext_test.go +++ b/modules/caddyhttp/templates/tplcontext_test.go @@ -290,11 +290,13 @@ func TestSplitFrontMatter(t *testing.T) { for i, test := range []struct { input string expect string + body string }{ { // yaml with windows newline input: "---\r\ntitle: Welcome\r\n---\r\n# Test\\r\\n", expect: `Welcome`, + body: "\r\n# Test\\r\\n", }, { // yaml @@ -303,6 +305,16 @@ title: Welcome --- ### Test`, expect: `Welcome`, + body: "\n### Test", + }, + { + // yaml with dots for closer + input: `--- +title: Welcome +... +### Test`, + expect: `Welcome`, + body: "\n### Test", }, { // toml @@ -311,6 +323,7 @@ title = "Welcome" +++ ### Test`, expect: `Welcome`, + body: "\n### Test", }, { // json @@ -319,12 +332,16 @@ title = "Welcome" } ### Test`, expect: `Welcome`, + body: "\n### Test", }, } { result, _ := context.funcSplitFrontMatter(test.input) if result.Meta["title"] != test.expect { t.Errorf("Test %d: Expected %s, found %s. Input was SplitFrontMatter(%s)", i, test.expect, result.Meta["title"], test.input) } + if result.Body != test.body { + t.Errorf("Test %d: Expected body %s, found %s. Input was SplitFrontMatter(%s)", i, test.body, result.Body, test.input) + } } } -- cgit v1.2.3