Open platform to collect and prioritize feedback
package tpl_test
import (
"encoding/json"
"testing"
. "github.com/getfider/fider/app/pkg/assert"
"github.com/getfider/fider/app/pkg/tpl"
)
func TestTextTemplate_Markdown(t *testing.T) {
RegisterT(t)
tmpl, err := tpl.GetTextTemplate("test", "{{ markdown .description }}")
Expect(err).IsNil()
for input, expected := range map[string]string{
"**Tom & Jerry** integration": "Tom & Jerry integration",
"Support `<details>` blocks": "Support <details> blocks",
"Hey <!channel> look": "Hey <!channel> look",
"Hey <!channel> look": "Hey <!channel> look",
"Hey `<!channel>` look": "Hey <!channel> look",
"Hi <img src=x onerror=alert(1)>": "Hi <img src=x onerror=alert(1)>",
} {
result, err := tpl.Execute(tmpl, map[string]any{"description": input})
Expect(err).IsNil()
Expect(result).Equals(expected)
}
}
func TestTextTemplate_Markdown_QuotedAsJSON(t *testing.T) {
RegisterT(t)
tmpl, err := tpl.GetTextTemplate("test", `{"m": {{ quote (markdown .description) }}}`)
Expect(err).IsNil()
result, err := tpl.Execute(tmpl, map[string]any{"description": "Tom & Jerry\n\nUse `List<String>` > <!channel>"})
Expect(err).IsNil()
var payload map[string]string
Expect(json.Unmarshal([]byte(result), &payload)).IsNil()
Expect(payload["m"]).Equals("Tom & Jerry\nUse List<String> > <!channel>")
}