Skip to content
quarry Artifact [f59039b544]
Login

Artifact [f59039b544]

Artifact f59039b544cd238187c67e674fc45f882bc01313266331b56997cb76472669fa:


package chat

import "testing"

// Fossil's artifact clause arrives as HTML; the channel holds markdown
// links at the upstream instead, and nothing but http(s) or a path.
func TestFossilAnchorsBecomeMarkdownAtTheUpstream(t *testing.T) {
	up := "https://fossil.example/home"
	for in, want := range map[string]string{
		"x (check-in: <a href='/r/libfossil/info/6df13e'>6df13e</a>, user: <a href='/r/libfossil/timeline?u=d&amp;c=6df'>d</a>)": "x (check-in: [6df13e](https://fossil.example/r/libfossil/info/6df13e), user: [d](https://fossil.example/r/libfossil/timeline?u=d&c=6df))",
		`<a href="javascript:alert(1)">click</a>`: "click",
		`<a href='//evil.example/x'>x</a>`:        "x",
		"no anchors here":                         "no anchors here",
	} {
		if got := anchorsAsMarkdown(in, up); got != want {
			t.Errorf("FAIL: %q\n got %q\nwant %q", in, got, want)
		}
	}
	t.Log("ok")
}

// Fossil's robots write formatting markup too; the channel keeps the
// words. Prose that only looks like a tag is left as it was.
func TestFossilFormattingTagsAreDropped(t *testing.T) {
	for in, want := range map[string]string{
		"<h1 class='error'>Shutting down httpd due to system load: possible crawler swarm</h1>": "Shutting down httpd due to system load: possible crawler swarm",
		"a <b>bold</b> word<br>":         "a bold word",
		"use <dive> here, and 3 < 4 > 2": "use <dive> here, and 3 < 4 > 2",
	} {
		if got := StripFossilFormatting(in); got != want {
			t.Errorf("FAIL: %q -> %q, want %q", in, got, want)
		}
	}
	t.Log("ok")
}