Fix shortcode detection in RenderString

Fixes #10654
This commit is contained in:
Bjørn Erik Pedersen
2023-01-26 10:30:25 +01:00
parent 4ef9baf5bd
commit 168858331f
4 changed files with 78 additions and 2 deletions

View File

@@ -19,6 +19,8 @@ import (
"fmt"
"io"
"io/ioutil"
"regexp"
"strings"
"github.com/gohugoio/hugo/parser/metadecoders"
)
@@ -234,3 +236,14 @@ func IsProbablySourceOfItems(source []byte, items Items) bool {
return true
}
var hasShortcodeRe = regexp.MustCompile(`{{[%,<][^\/]`)
// HasShortcode returns true if the given string contains a shortcode.
func HasShortcode(s string) bool {
// Fast path for the common case.
if !strings.Contains(s, "{{") {
return false
}
return hasShortcodeRe.MatchString(s)
}