diff options
author | Unknwon <u@gogs.io> | 2015-11-21 21:06:11 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-11-21 21:06:11 -0500 |
commit | f12832c61e95a9eff1195f543fc11d1113dae4fc (patch) | |
tree | ba577eb19c83ef5709cc9120a3d75358611e3ae5 /modules | |
parent | dcc740fd26d519e7c59ec3d56012a7b961d3e912 (diff) | |
download | gitea-f12832c61e95a9eff1195f543fc11d1113dae4fc.tar.gz gitea-f12832c61e95a9eff1195f543fc11d1113dae4fc.zip |
fix possible panic
Diffstat (limited to 'modules')
-rw-r--r-- | modules/base/markdown.go | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/modules/base/markdown.go b/modules/base/markdown.go index 53eee4b3e4..cf7a3193f8 100644 --- a/modules/base/markdown.go +++ b/modules/base/markdown.go @@ -271,14 +271,24 @@ OUTER_LOOP: tagName := token.Data // If this is an excluded tag, we skip processing all output until a close tag is encountered. if strings.EqualFold("a", tagName) || strings.EqualFold("code", tagName) || strings.EqualFold("pre", tagName) { + stackNum := 1 for html.ErrorToken != tokenizer.Next() { token = tokenizer.Token() // Copy the token to the output verbatim buf.WriteString(token.String()) - // If this is the close tag, we are done + + if token.Type == html.StartTagToken { + stackNum++ + } + + // If this is the close tag to the outer-most, we are done if token.Type == html.EndTagToken && strings.EqualFold(tagName, token.Data) { - break + stackNum-- + + if stackNum == 0 { + break + } } } continue OUTER_LOOP |