diff --git a/inline.go b/inline.go index 0e7cb86..0348dbf 100644 --- a/inline.go +++ b/inline.go @@ -718,7 +718,7 @@ func autoLink(p *parser, out *bytes.Buffer, data []byte, offset int) int { return linkEnd - rewind } -var validUris = [][]byte{[]byte("http://"), []byte("https://"), []byte("ftp://"), []byte("mailto://")} +var validUris = [][]byte{[]byte("http://"), []byte("https://"), []byte("ftp://"), []byte("mailto://"), []byte("/")} func isSafeLink(link []byte) bool { for _, prefix := range validUris { diff --git a/inline_test.go b/inline_test.go index b7a1688..a9862ce 100644 --- a/inline_test.go +++ b/inline_test.go @@ -32,6 +32,10 @@ func doTestsInline(t *testing.T, tests []string) { doTestsInlineParam(t, tests, 0, 0) } +func doSafeTestsInline(t *testing.T, tests []string) { + doTestsInlineParam(t, tests, 0, HTML_SAFELINK) +} + func doTestsInlineParam(t *testing.T, tests []string, extensions, htmlFlags int) { // catch and report panics var candidate string @@ -417,6 +421,30 @@ func TestInlineLink(t *testing.T) { doTestsInline(t, tests) } +func TestSafeInlineLink(t *testing.T) { + var tests = []string{ + "[foo](/bar/)\n", + "
\n", + + "[foo](http://bar/)\n", + "\n", + + "[foo](https://bar/)\n", + "\n", + + "[foo](ftp://bar/)\n", + "\n", + + "[foo](mailto://bar/)\n", + "\n", + + // Not considered safe + "[foo](baz://bar/)\n", + "foo
\n", + } + doSafeTestsInline(t, tests) +} + func TestReferenceLink(t *testing.T) { var tests = []string{ "[link][ref]\n",