Fix bug in autolink with trailing semicolon In case the link ends with escaped html entity, the semicolon is a part of the link and should not be interpreted as punctuation.
Vytautas Ĺ altenis vytas@rtfb.lt
Sun, 26 Jan 2014 23:40:26 +0200
2 files changed,
17 insertions(+),
1 deletions(-)
M
inline.go
→
inline.go
@@ -617,6 +617,14 @@
return end } +func linkEndsWithEntity(data []byte, linkEnd int) bool { + entityRanges := htmlEntity.FindAllIndex(data[:linkEnd], -1) + if entityRanges != nil && entityRanges[len(entityRanges)-1][1] == linkEnd { + return true + } + return false +} + func autoLink(p *parser, out *bytes.Buffer, data []byte, offset int) int { // quick check to rule out most false hits on ':' if p.insideLink || len(data) < offset+3 || data[offset+1] != '/' || data[offset+2] != '/' {@@ -659,7 +667,12 @@ linkEnd++
} // Skip punctuation at the end of the link - if (data[linkEnd-1] == '.' || data[linkEnd-1] == ',' || data[linkEnd-1] == ';') && data[linkEnd-2] != '\\' { + if (data[linkEnd-1] == '.' || data[linkEnd-1] == ',') && data[linkEnd-2] != '\\' { + linkEnd-- + } + + // But don't skip semicolon if it's a part of escaped entity: + if data[linkEnd-1] == ';' && data[linkEnd-2] != '\\' && !linkEndsWithEntity(data, linkEnd) { linkEnd-- }
M
inline_test.go
→
inline_test.go
@@ -698,6 +698,9 @@ "<p><a href=\"http://foo.com/viewtopic.php?f=18&t=297\">http://foo.com/viewtopic.php?f=18&t=297</a></p>\n",
"http://foo.com/viewtopic.php?param="18"zz", "<p><a href=\"http://foo.com/viewtopic.php?param="18"zz\">http://foo.com/viewtopic.php?param="18"zz</a></p>\n", + + "http://foo.com/viewtopic.php?param="18"", + "<p><a href=\"http://foo.com/viewtopic.php?param="18"\">http://foo.com/viewtopic.php?param="18"</a></p>\n", } doTestsInline(t, tests) }