mirror of
https://github.com/danog/blackfriday.git
synced 2025-01-22 13:21:36 +01:00
fix duplicate and recursive footnotes. (#241)
Fix the infinite loop when there is a self-refer footnote by checking if the reference is already added into parser.notes. It also fixes of creating duplicate footnotes through this modification. Add coresponding testcase.
This commit is contained in:
parent
0ba0f2b6ed
commit
a20399916c
@ -498,7 +498,7 @@ func link(p *parser, out *bytes.Buffer, data []byte, offset int) int {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
if t == linkDeferredFootnote {
|
if t == linkDeferredFootnote && !p.isFootnote(lr) {
|
||||||
lr.noteId = len(p.notes) + 1
|
lr.noteId = len(p.notes) + 1
|
||||||
p.notes = append(p.notes, lr)
|
p.notes = append(p.notes, lr)
|
||||||
}
|
}
|
||||||
|
@ -1023,6 +1023,28 @@ what happens here
|
|||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
|
`,
|
||||||
|
`testing footnotes.[^a]
|
||||||
|
|
||||||
|
test footnotes the second.[^b]
|
||||||
|
|
||||||
|
[^a]: This is the first note[^a].
|
||||||
|
[^b]: this is the second note.[^a]
|
||||||
|
`,
|
||||||
|
`<p>testing footnotes.<sup class="footnote-ref" id="fnref:a"><a rel="footnote" href="#fn:a">1</a></sup></p>
|
||||||
|
|
||||||
|
<p>test footnotes the second.<sup class="footnote-ref" id="fnref:b"><a rel="footnote" href="#fn:b">2</a></sup></p>
|
||||||
|
<div class="footnotes">
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li id="fn:a">This is the first note<sup class="footnote-ref" id="fnref:a"><a rel="footnote" href="#fn:a">1</a></sup>.
|
||||||
|
</li>
|
||||||
|
<li id="fn:b">this is the second note.<sup class="footnote-ref" id="fnref:a"><a rel="footnote" href="#fn:a">1</a></sup>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1076,6 +1098,34 @@ func TestNestedFootnotes(t *testing.T) {
|
|||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
|
`,
|
||||||
|
`This uses footnote A.[^A]
|
||||||
|
|
||||||
|
This uses footnote C.[^C]
|
||||||
|
|
||||||
|
[^A]:
|
||||||
|
A note. use itself.[^A]
|
||||||
|
[^B]:
|
||||||
|
B note, uses A to test duplicate.[^A]
|
||||||
|
[^C]:
|
||||||
|
C note, uses B.[^B]
|
||||||
|
`,
|
||||||
|
`<p>This uses footnote A.<sup class="footnote-ref" id="fnref:A"><a rel="footnote" href="#fn:A">1</a></sup></p>
|
||||||
|
|
||||||
|
<p>This uses footnote C.<sup class="footnote-ref" id="fnref:C"><a rel="footnote" href="#fn:C">2</a></sup></p>
|
||||||
|
<div class="footnotes">
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
|
||||||
|
<ol>
|
||||||
|
<li id="fn:A">A note. use itself.<sup class="footnote-ref" id="fnref:A"><a rel="footnote" href="#fn:A">1</a></sup>
|
||||||
|
</li>
|
||||||
|
<li id="fn:C">C note, uses B.<sup class="footnote-ref" id="fnref:B"><a rel="footnote" href="#fn:B">3</a></sup>
|
||||||
|
</li>
|
||||||
|
<li id="fn:B">B note, uses A to test duplicate.<sup class="footnote-ref" id="fnref:A"><a rel="footnote" href="#fn:A">1</a></sup>
|
||||||
|
</li>
|
||||||
|
</ol>
|
||||||
|
</div>
|
||||||
`,
|
`,
|
||||||
}
|
}
|
||||||
doTestsInlineParam(t, tests, Options{Extensions: EXTENSION_FOOTNOTES}, 0,
|
doTestsInlineParam(t, tests, Options{Extensions: EXTENSION_FOOTNOTES}, 0,
|
||||||
|
10
markdown.go
10
markdown.go
@ -241,6 +241,16 @@ func (p *parser) getRef(refid string) (ref *reference, found bool) {
|
|||||||
return ref, found
|
return ref, found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *parser) isFootnote(ref *reference) bool {
|
||||||
|
for _, v := range p.notes {
|
||||||
|
if string(ref.link) == string(v.link) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Public interface
|
// Public interface
|
||||||
|
Loading…
x
Reference in New Issue
Block a user