diff --git a/inline.go b/inline.go index 952aa63..41225ce 100644 --- a/inline.go +++ b/inline.go @@ -617,6 +617,14 @@ func entity(p *parser, out *bytes.Buffer, data []byte, offset int) int { 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 @@ func autoLink(p *parser, out *bytes.Buffer, data []byte, offset int) int { } // 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-- } diff --git a/inline_test.go b/inline_test.go index aea6bf1..c6e8d10 100644 --- a/inline_test.go +++ b/inline_test.go @@ -698,6 +698,9 @@ func TestAutoLink(t *testing.T) { "http://foo.com/viewtopic.php?param="18"zz", "

http://foo.com/viewtopic.php?param="18"zz

\n", + + "http://foo.com/viewtopic.php?param="18"", + "

http://foo.com/viewtopic.php?param="18"

\n", } doTestsInline(t, tests) }