Don't run nil funcs from magic map

This commit is contained in:
Sven Windisch 2021-12-14 17:41:36 +01:00
parent c37abe9980
commit fe16921713
2 changed files with 16 additions and 1 deletions

View file

@ -401,7 +401,7 @@ var VariablesMap map[string]bool = map[string]bool{
func (a *Article) renderTemplateMagic(name string, params map[string]string) string {
renderer, ok := MagicMap[name]
text := ""
if ok {
if ok && renderer != nil {
text = renderer(name, params)
}

View file

@ -54,3 +54,18 @@ func TestMagicMap(t *testing.T) {
t.Error("Error in magic map ", l)
}
}
func TestNilFunc(t *testing.T) {
mw := "{{DISPLAYTITLE}}"
t.Log(mw)
a, err := ParseArticle("Test", mw, &DummyPageGetter{})
if err != nil {
t.Error("Error:", err)
}
l := a.GetText()
if strings.TrimSpace(l) != "" {
t.Error("NIL entry in magic map not caught", l)
}
}