Skip to content

Commit 07bd09e

Browse files
committed
Recover panic in orgmode.Render if bad orgfile (go-gitea#4982)
This PR protects against the panic referred to in chaseadmsio/goorgeous#82 by recovering from the panic and just returning the raw bytes if there is an error. Signed-off-by: Andrew Thornton <[email protected]>
1 parent a967cf9 commit 07bd09e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

modules/markup/orgmode/orgmode.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package markup
66

77
import (
8+
"code.gitea.io/gitea/modules/log"
89
"code.gitea.io/gitea/modules/markup"
910
"code.gitea.io/gitea/modules/markup/markdown"
1011

@@ -31,7 +32,13 @@ func (Parser) Extensions() []string {
3132
}
3233

3334
// Render renders orgmode rawbytes to HTML
34-
func Render(rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) []byte {
35+
func Render(rawBytes []byte, urlPrefix string, metas map[string]string, isWiki bool) (result []byte) {
36+
defer func() {
37+
if err := recover(); err != nil {
38+
log.Error(4, "Panic in orgmode.Render: %v Just returning the rawBytes", err)
39+
result = rawBytes
40+
}
41+
}()
3542
htmlFlags := blackfriday.HTML_USE_XHTML
3643
htmlFlags |= blackfriday.HTML_SKIP_STYLE
3744
htmlFlags |= blackfriday.HTML_OMIT_CONTENTS
@@ -40,9 +47,8 @@ func Render(rawBytes []byte, urlPrefix string, metas map[string]string, isWiki b
4047
URLPrefix: urlPrefix,
4148
IsWiki: isWiki,
4249
}
43-
44-
result := goorgeous.Org(rawBytes, renderer)
45-
return result
50+
result = goorgeous.Org(rawBytes, renderer)
51+
return
4652
}
4753

4854
// RenderString reners orgmode string to HTML string

0 commit comments

Comments
 (0)