mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-22 01:44:24 +01:00
Merge pull request '[BUG] Don't panic on empty blockquote' (#4602) from gusted/forgejo-md-panic into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/4602 Reviewed-by: Gergely Nagy <algernon@noreply.codeberg.org>
This commit is contained in:
commit
15540445d9
|
@ -36,6 +36,10 @@ func (g *GitHubCalloutTransformer) Transform(node *ast.Document, reader text.Rea
|
|||
|
||||
switch v := n.(type) {
|
||||
case *ast.Blockquote:
|
||||
if v.ChildCount() == 0 {
|
||||
return ast.WalkContinue, nil
|
||||
}
|
||||
|
||||
// We only want attention blockquotes when the AST looks like:
|
||||
// Text: "["
|
||||
// Text: "!TYPE"
|
||||
|
|
|
@ -25,6 +25,10 @@ func (g *GitHubLegacyCalloutTransformer) Transform(node *ast.Document, reader te
|
|||
|
||||
switch v := n.(type) {
|
||||
case *ast.Blockquote:
|
||||
if v.ChildCount() == 0 {
|
||||
return ast.WalkContinue, nil
|
||||
}
|
||||
|
||||
// The first paragraph contains the callout type.
|
||||
firstParagraph := v.FirstChild()
|
||||
if firstParagraph.ChildCount() < 1 {
|
||||
|
|
|
@ -1342,3 +1342,17 @@ key: value
|
|||
</tbody>
|
||||
</table>`)
|
||||
}
|
||||
|
||||
func TestCallout(t *testing.T) {
|
||||
setting.AppURL = AppURL
|
||||
|
||||
test := func(input, expected string) {
|
||||
buffer, err := markdown.RenderString(&markup.RenderContext{
|
||||
Ctx: git.DefaultContext,
|
||||
}, input)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
|
||||
}
|
||||
|
||||
test(">\n0", "<blockquote>\n</blockquote>\n<p>0</p>")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue