Skip to content

fix the order in which template Funcs are applied #546

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2022
Merged

fix the order in which template Funcs are applied #546

merged 1 commit into from
Oct 3, 2022

Conversation

Googlom
Copy link
Contributor

@Googlom Googlom commented Aug 22, 2022

Solution to #544.

The bug occured because layout.template methods result...

telebot/layout/layout.go

Lines 511 to 520 in c6bead1

func (lt *Layout) template(tmpl *template.Template, locale string) *template.Template {
funcs := make(template.FuncMap)
// Redefining built-in blank functions
funcs["config"] = lt.String
funcs["text"] = func(k string, args ...interface{}) string { return lt.TextLocale(locale, k, args...) }
funcs["locale"] = func() string { return locale }
return tmpl.Funcs(funcs)
}

was overwritten by method template.Funcs(lt.funcs) which applies...

telebot/layout/layout.go

Lines 285 to 289 in c6bead1

tmpl, err := lt.template(template.New(k), locale).Funcs(lt.funcs).Parse(string(data))
if err != nil {
log.Println("telebot/layout:", err)
return nil
}

builtinFuncs:

telebot/layout/layout.go

Lines 99 to 104 in c6bead1

var builtinFuncs = template.FuncMap{
// Built-in blank and helper functions.
"locale": func() string { return "" },
"config": func(string) string { return "" },
"text": func(string, ...interface{}) string { return "" },
}

@Googlom Googlom closed this Aug 22, 2022
@Googlom Googlom deleted the v3-fix-layout-button branch August 22, 2022 11:48
@Googlom Googlom restored the v3-fix-layout-button branch August 22, 2022 12:30
@Googlom Googlom reopened this Aug 22, 2022
@demget demget added this to the v3.0.2 milestone Oct 2, 2022
@demget demget merged commit d4c80e6 into tucnak:v3 Oct 3, 2022
@demget
Copy link
Collaborator

demget commented Oct 3, 2022

Thank you, a good catch!

@demget demget modified the milestones: v3.0.2, v3.1 Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants