aboutsummaryrefslogtreecommitdiffstats
path: root/modules/markup/markdown/goldmark.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-05-11 00:14:49 +0100
committerGitHub <noreply@github.com>2020-05-11 00:14:49 +0100
commit742e26f5a5dab8768558231cb88801911b9abaa7 (patch)
tree503132c419de71a164f8e8dd236e6146f8f4b7b6 /modules/markup/markdown/goldmark.go
parentc9187b81164757c67a0f83ef34b001f7d38c264a (diff)
downloadgitea-742e26f5a5dab8768558231cb88801911b9abaa7.tar.gz
gitea-742e26f5a5dab8768558231cb88801911b9abaa7.zip
Prevent 500 with badly formed task list (#11328)
Fix #11317 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/markup/markdown/goldmark.go')
-rw-r--r--modules/markup/markdown/goldmark.go38
1 files changed, 22 insertions, 16 deletions
diff --git a/modules/markup/markdown/goldmark.go b/modules/markup/markdown/goldmark.go
index 6a40a86836..bf02a22d5e 100644
--- a/modules/markup/markdown/goldmark.go
+++ b/modules/markup/markdown/goldmark.go
@@ -125,24 +125,30 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
}
v.Destination = link
case *ast.List:
- if v.HasChildren() && v.FirstChild().HasChildren() && v.FirstChild().FirstChild().HasChildren() {
- if _, ok := v.FirstChild().FirstChild().FirstChild().(*east.TaskCheckBox); ok {
- v.SetAttributeString("class", []byte("task-list"))
- children := make([]ast.Node, 0, v.ChildCount())
- child := v.FirstChild()
- for child != nil {
- children = append(children, child)
- child = child.NextSibling()
+ if v.HasChildren() {
+ children := make([]ast.Node, 0, v.ChildCount())
+ child := v.FirstChild()
+ for child != nil {
+ children = append(children, child)
+ child = child.NextSibling()
+ }
+ v.RemoveChildren(v)
+
+ for _, child := range children {
+ listItem := child.(*ast.ListItem)
+ if !child.HasChildren() || !child.FirstChild().HasChildren() {
+ v.AppendChild(v, child)
+ continue
}
- v.RemoveChildren(v)
-
- for _, child := range children {
- listItem := child.(*ast.ListItem)
- newChild := NewTaskCheckBoxListItem(listItem)
- taskCheckBox := child.FirstChild().FirstChild().(*east.TaskCheckBox)
- newChild.IsChecked = taskCheckBox.IsChecked
- v.AppendChild(v, newChild)
+ taskCheckBox, ok := child.FirstChild().FirstChild().(*east.TaskCheckBox)
+ if !ok {
+ v.AppendChild(v, child)
+ continue
}
+ newChild := NewTaskCheckBoxListItem(listItem)
+ newChild.IsChecked = taskCheckBox.IsChecked
+ newChild.SetAttributeString("class", []byte("task-list-item"))
+ v.AppendChild(v, newChild)
}
}
}