package web
import (
"encoding/json"
"os"
"testing"
)
// Equipo's lines may carry Markdown links. Base links only web addresses;
// everything else, raw HTML included, stays text.
func TestRichText(t *testing.T) {
for in, want := range map[string]string{
"Published at https://site-sample.example.test/.": `Published at https://site-sample.example.test/.`,
"See [docs](https://docs.test/a?b=1&c=2)": `See docs`,
"[x](javascript:alert(1))": `[x](javascript:alert(1))`,
"[x](data:text/html,hi)": `[x](data:text/html,<b>hi</b>)`,
" bold": `<script>alert(1)</script> <b>bold</b>`,
"[](https://a.test/)": `<img src=x onerror=alert(1)>`,
"[x](/tasks/../admin)": `[x](/tasks/../admin)`,
"[x](//evil.test/)": `[x](//evil.test/)`,
"plain & simple": `plain & simple`,
} {
if got := string(richText(in)); got != want {
t.Errorf("richText(%q)\n got %s\nwant %s", in, got, want)
}
}
}
// The Assistant never points at the team's pages: a /tasks/ link is
// text, while a web address still links.
func TestRichTextHasNoTaskLinks(t *testing.T) {
for in, want := range map[string]string{
"[x](/tasks/tk1)": `[x](/tasks/tk1)`,
"See [it](https://site.example.test/)": `See it`,
} {
if got := string(richText(in)); got != want {
t.Errorf("richText(%q)\n got %s\nwant %s", in, got, want)
}
}
}
// The Assistant writes a little Markdown (plan decision D16): bold,
// italics, bullet and numbered lists. Anything else stays text, links keep
// their rules inside lists, and what is bold is still escaped.
func TestRichTextMarkdown(t *testing.T) {
for _, c := range []struct{ in, want string }{
{"**Done.** Your site is up", `Done. Your site is up`},
{"*soon*", `soon`},
{"_soon_", `soon`},
{"a_b_c", `a_b_c`},
{"**x**", `<b>x</b>`},
{"Three things:\n- Docs\n- Sheets\n- [Calendar](https://cal.test/)", `Three things: