When calling Render with a layout and a nil binding: panic: assignment to entry in nil map
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 48/100
Research direction
Start in jet/jet.go at jetVarMap and Render, especially the layout branch that calls bind.Set. Reproduce Render with a layout and a nil binding, then verify that the nil-binding path no longer panics while the existing layout behavior remains intact.
Written by the indexing model from the issue text.
Description
The issue is that in jetVarMap it assumes that a nil binding should result in a nil jet.VarMap.
But if a layout is specified, it is then used to set a function and panics:
This could be solved either by replacing var bind jet.VarMap with bind := make(jet.VarMap) or by checking if bind is nil (and makeing it if not) in Render right after if len(layout) > 0 {.
// var bind jet.VarMap
bind := make(jet.VarMap)
Or in Render
bind := jetVarMap(binding)
if len(layout) > 0 {
if bind == nil {
bind = make(jet.VarMap)
}
lay, err := e.Templates.GetTemplate(layout[0])
if err != nil {
return err
}
bind.Set(e.layout, func() {
_ = tmpl.Execute(out, bind, nil)
})
return lay.Execute(out, bind, nil)
}
I would send a pull request, but I'm not sure if it matters to you which way it is fixed. I would think it would be much clearer to put it in jetVarMap and get rid of the other calls to make there, but I guess there was a reason to not do that in the first place.
The work around is for the caller of Render to just specify an empty jet.VarMap or fiber.Map but that is not obvious and panicing from forgetting is not great.
- Dominant language
- Go
- Stars
- 314
- Forks
- 61
- Avg merge
- 4h 35m
- Merged PRs (30d)
- 12
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from gofiber/template
-
✏️ Feature
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
✏️ Feature 👍 Accepting PR
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
gonja support? Open👍 Accepting PR 💡 Help wanted 🤔 Question
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
🤔 Question
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
🤔 Question
Difficulty 3/5 1-2 days Newbie friendliness 25/100
All issues in gofiber/template
Similar issues
-
optimization optimization:agents-md-curator
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
githubnext/gh-aw-cao#13143 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
blinklabs-io/bursa#904 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
yanet-platform/ipfw-go#129 ·
-
bug confmap/provider/googlesecretmanagerprovider needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
open-telemetry/opentelemetry-collector-contrib#51273 · 2 comments ·
-
bug: AI Gateway client filter lists "Unknown" twice when NULL and literal Unknown clients coexist Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 90/100