Fix bug in autolink termination

Detect the end of link when it is immediately followed by an element.
This commit is contained in:
Vytautas Šaltenis 2014-01-25 21:59:38 +02:00
parent 9fc8c9d866
commit f2d43f69a4
2 changed files with 8 additions and 1 deletions

View File

@ -654,7 +654,7 @@ func autoLink(p *parser, out *bytes.Buffer, data []byte, offset int) int {
} }
linkEnd := 0 linkEnd := 0
for linkEnd < len(data) && !isspace(data[linkEnd]) { for linkEnd < len(data) && !isEndOfLink(data[linkEnd]) {
linkEnd++ linkEnd++
} }
@ -737,6 +737,10 @@ func autoLink(p *parser, out *bytes.Buffer, data []byte, offset int) int {
return linkEnd - rewind return linkEnd - rewind
} }
func isEndOfLink(char byte) bool {
return isspace(char) || char == '<'
}
var validUris = [][]byte{[]byte("http://"), []byte("https://"), []byte("ftp://"), []byte("mailto://"), []byte("/")} var validUris = [][]byte{[]byte("http://"), []byte("https://"), []byte("ftp://"), []byte("mailto://"), []byte("/")}
func isSafeLink(link []byte) bool { func isSafeLink(link []byte) bool {

View File

@ -689,6 +689,9 @@ func TestAutoLink(t *testing.T) {
"(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (part two: <a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a>)).\n", "(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (part two: <a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a>)).\n",
"<p>(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (part two: <a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a>)).</p>\n", "<p>(<a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a> (part two: <a href=\"http://www.fancy.com/A_B\">http://www.fancy.com/A_B</a>)).</p>\n",
"http://www.foo.com<br />\n",
"<p><a href=\"http://www.foo.com\">http://www.foo.com</a><br /></p>\n",
} }
doTestsInline(t, tests) doTestsInline(t, tests)
} }