mirror of
https://github.com/russross/blackfriday.git
synced 2024-03-22 13:40:34 +08:00
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.
This commit is contained in:
parent
b0bdfbec4c
commit
e5937643a9
15
inline.go
15
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--
|
||||
}
|
||||
|
||||
|
|
|
@ -698,6 +698,9 @@ func TestAutoLink(t *testing.T) {
|
|||
|
||||
"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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user