Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Fix #2211 #2216

Merged
merged 2 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion default_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ var mapType = reflect.ValueOf(map[string]interface{}{}).Type()
// Redirect a request with the given status to the given URL.
func (d *DefaultContext) Redirect(status int, url string, args ...interface{}) error {
if d.Session() != nil {
d.Flash().Clear()
d.Flash().persist(d.Session())
if err := d.Session().Save(); err != nil {
return HTTPError{Status: http.StatusInternalServerError, Cause: err}
Expand Down
2 changes: 1 addition & 1 deletion error_templates.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package buffalo

import (
_ "embed"
_ "embed" // needed to embed the templates.
)

var (
Expand Down
29 changes: 28 additions & 1 deletion flash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package buffalo
import (
"net/http"
"testing"
"text/template"

"github.com/gobuffalo/buffalo/render"
"github.com/gobuffalo/httptest"
Expand Down Expand Up @@ -120,4 +121,30 @@ func Test_FlashRenderCustomKeyNotDefined(t *testing.T) {
const customKeyTPL = `
{{#each flash.other as |k value|}}
{{value}}
{{/each}}`
{{/each}}
`

func Test_FlashNotClearedOnRedirect(t *testing.T) {
r := require.New(t)
a := New(Options{})
rr := render.New(render.Options{})

a.GET("/flash", func(c Context) error {
c.Flash().Add("success", "Antonio, you're welcome!")
return c.Redirect(http.StatusSeeOther, "/")
})

a.GET("/", func(c Context) error {
template := `Message: <%= flash["success"] %>`
return c.Render(http.StatusCreated, rr.String(template))
})

w := httptest.New(a)
res := w.HTML("/flash").Get()
r.Equal(res.Code, http.StatusSeeOther)
r.Equal(res.Location(), "/")

res = w.HTML("/").Get()
r.Contains(res.Body.String(), template.HTMLEscapeString("Antonio, you're welcome!"))

}