mirror of
https://github.com/caddyserver/caddy.git
synced 2024-11-29 20:24:11 +08:00
Fix for Issue 72: Markdown: 500 for YAML metadata
This commit is contained in:
parent
018fd21741
commit
8394d72f48
|
@ -154,6 +154,19 @@ func (y *YAMLMetadataParser) Parse(b []byte) ([]byte, error) {
|
||||||
if err := yaml.Unmarshal(b, &m); err != nil {
|
if err := yaml.Unmarshal(b, &m); err != nil {
|
||||||
return markdown, err
|
return markdown, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// convert variables (if present) to map[string]interface{}
|
||||||
|
// to match expected type
|
||||||
|
if vars, ok := m["variables"].(map[interface{}]interface{}); ok {
|
||||||
|
vars1 := make(map[string]interface{})
|
||||||
|
for k, v := range vars {
|
||||||
|
if key, ok := k.(string); ok {
|
||||||
|
vars1[key] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m["variables"] = vars1
|
||||||
|
}
|
||||||
|
|
||||||
y.metadata.load(m)
|
y.metadata.load(m)
|
||||||
return markdown, nil
|
return markdown, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,13 +35,13 @@ var YAML = [4]string{`
|
||||||
title : A title
|
title : A title
|
||||||
template : default
|
template : default
|
||||||
variables :
|
variables :
|
||||||
- name : value
|
name : value
|
||||||
`,
|
`,
|
||||||
`---
|
`---
|
||||||
title : A title
|
title : A title
|
||||||
template : default
|
template : default
|
||||||
variables :
|
variables :
|
||||||
- name : value
|
name : value
|
||||||
---
|
---
|
||||||
Page content
|
Page content
|
||||||
`,
|
`,
|
||||||
|
@ -49,7 +49,7 @@ Page content
|
||||||
title : A title
|
title : A title
|
||||||
template : default
|
template : default
|
||||||
variables :
|
variables :
|
||||||
- name : value
|
name : value
|
||||||
`,
|
`,
|
||||||
`title : A title template : default variables : name : value`,
|
`title : A title template : default variables : name : value`,
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ func TestParsers(t *testing.T) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
return len(m.Variables) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
data := []struct {
|
data := []struct {
|
||||||
|
@ -135,7 +135,7 @@ func TestParsers(t *testing.T) {
|
||||||
md, err := v.parser.Parse([]byte(v.testData[1]))
|
md, err := v.parser.Parse([]byte(v.testData[1]))
|
||||||
check(t, err)
|
check(t, err)
|
||||||
if !compare(v.parser.Metadata()) {
|
if !compare(v.parser.Metadata()) {
|
||||||
t.Fatalf("Expected %v, found %v for %v", expected, v.parser.Metadata().Variables, v.name)
|
t.Fatalf("Expected %v, found %v for %v", expected, v.parser.Metadata(), v.name)
|
||||||
}
|
}
|
||||||
if "Page content" != strings.TrimSpace(string(md)) {
|
if "Page content" != strings.TrimSpace(string(md)) {
|
||||||
t.Fatalf("Expected %v, found %v for %v", "Page content", string(md), v.name)
|
t.Fatalf("Expected %v, found %v for %v", "Page content", string(md), v.name)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user