diff options
author | mrsdizzie <info@mrsdizzie.com> | 2020-12-03 22:08:48 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-04 04:08:48 +0100 |
commit | 798fdeae4545c1558a82d95d34165cc274080ab8 (patch) | |
tree | aef88493e6aeb284407b005dd7046fce82cf9538 /modules | |
parent | 87997cccbb47c0219a0c0955cf09eadfef588b46 (diff) | |
download | gitea-798fdeae4545c1558a82d95d34165cc274080ab8.tar.gz gitea-798fdeae4545c1558a82d95d34165cc274080ab8.zip |
Fix crash in short link processor (#13839) (#13841)
Fixes #13819
Diffstat (limited to 'modules')
-rw-r--r-- | modules/markup/html.go | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/modules/markup/html.go b/modules/markup/html.go index f5f811b59b..500261bf8f 100644 --- a/modules/markup/html.go +++ b/modules/markup/html.go @@ -632,16 +632,18 @@ func shortLinkProcessorFull(ctx *postProcessCtx, node *html.Node, noLink bool) { // When parsing HTML, x/net/html will change all quotes which are // not used for syntax into UTF-8 quotes. So checking val[0] won't // be enough, since that only checks a single byte. - if (strings.HasPrefix(val, "“") && strings.HasSuffix(val, "”")) || - (strings.HasPrefix(val, "‘") && strings.HasSuffix(val, "’")) { - const lenQuote = len("‘") - val = val[lenQuote : len(val)-lenQuote] - } else if (strings.HasPrefix(val, "\"") && strings.HasSuffix(val, "\"")) || - (strings.HasPrefix(val, "'") && strings.HasSuffix(val, "'")) { - val = val[1 : len(val)-1] - } else if strings.HasPrefix(val, "'") && strings.HasSuffix(val, "’") { - const lenQuote = len("‘") - val = val[1 : len(val)-lenQuote] + if len(val) > 1 { + if (strings.HasPrefix(val, "“") && strings.HasSuffix(val, "”")) || + (strings.HasPrefix(val, "‘") && strings.HasSuffix(val, "’")) { + const lenQuote = len("‘") + val = val[lenQuote : len(val)-lenQuote] + } else if (strings.HasPrefix(val, "\"") && strings.HasSuffix(val, "\"")) || + (strings.HasPrefix(val, "'") && strings.HasSuffix(val, "'")) { + val = val[1 : len(val)-1] + } else if strings.HasPrefix(val, "'") && strings.HasSuffix(val, "’") { + const lenQuote = len("‘") + val = val[1 : len(val)-lenQuote] + } } props[key] = val } |