diff options
author | Bjørn Erik Pedersen <[email protected]> | 2022-03-17 21:58:54 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2022-03-21 09:32:35 +0100 |
commit | 0e305d695820779a5c66fbe3434e3293911d7f98 (patch) | |
tree | af07f4be9ef8682cff914cbcf9d6e42e05c81434 /tpl | |
parent | 5adb81ce39a36214712762288c6aab9ebcff5e24 (diff) | |
download | hugo-0e305d695820779a5c66fbe3434e3293911d7f98.tar.gz hugo-0e305d695820779a5c66fbe3434e3293911d7f98.zip |
all: Use strings.Cut
Updates #9687
Diffstat (limited to 'tpl')
-rw-r--r-- | tpl/collections/apply.go | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/tpl/collections/apply.go b/tpl/collections/apply.go index 3b8de5f0e..9fd5c2d0c 100644 --- a/tpl/collections/apply.go +++ b/tpl/collections/apply.go @@ -107,15 +107,14 @@ func applyFnToThis(ctx context.Context, fn, this reflect.Value, args ...any) (re } func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) { - if !strings.ContainsRune(fname, '.') { + namespace, methodName, ok := strings.Cut(fname, ".") + if !ok { templ := ns.deps.Tmpl().(tpl.TemplateFuncGetter) return templ.GetFunc(fname) } - ss := strings.SplitN(fname, ".", 2) - // Namespace - nv, found := ns.lookupFunc(ss[0]) + nv, found := ns.lookupFunc(namespace) if !found { return reflect.Value{}, false } @@ -131,7 +130,7 @@ func (ns *Namespace) lookupFunc(fname string) (reflect.Value, bool) { nv = reflect.ValueOf(v) // method - m := hreflect.GetMethodByName(nv, ss[1]) + m := hreflect.GetMethodByName(nv, methodName) if m.Kind() == reflect.Invalid { return reflect.Value{}, false |