all repos — grayfriday @ e5937643a93cc2e494ee8ba93d03948e221333f5

blackfriday fork with a few changes

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
commit

e5937643a93cc2e494ee8ba93d03948e221333f5

parent

b0bdfbec4ceab22844aa766b3856aa95753ffde8

2 files changed, 17 insertions(+), 1 deletions(-)

jump to
M inline.goinline.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.goinline_test.go

@@ -698,6 +698,9 @@ "<p><a href=\"http://foo.com/viewtopic.php?f=18&amp;t=297\">http://foo.com/viewtopic.php?f=18&amp;t=297</a></p>\n",

"http://foo.com/viewtopic.php?param=&quot;18&quot;zz", "<p><a href=\"http://foo.com/viewtopic.php?param=&quot;18&quot;zz\">http://foo.com/viewtopic.php?param=&quot;18&quot;zz</a></p>\n", + + "http://foo.com/viewtopic.php?param=&quot;18&quot;", + "<p><a href=\"http://foo.com/viewtopic.php?param=&quot;18&quot;\">http://foo.com/viewtopic.php?param=&quot;18&quot;</a></p>\n", } doTestsInline(t, tests) }