PLAN: database backup and restore; messages survive #fragment redirects
The redirect helper put ?msg= after the #fragment, so "imported" and "saved" never showed after lead-source imports or campaign assignments. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -392,11 +392,16 @@ var flashes = map[string]string{
|
||||
|
||||
func redirect(w http.ResponseWriter, r *http.Request, path, msg string) {
|
||||
if msg != "" {
|
||||
// The message goes in the query, before any #fragment.
|
||||
base, frag, hasFrag := strings.Cut(path, "#")
|
||||
sep := "?"
|
||||
if strings.Contains(path, "?") {
|
||||
if strings.Contains(base, "?") {
|
||||
sep = "&"
|
||||
}
|
||||
path += sep + "msg=" + url.QueryEscape(msg)
|
||||
path = base + sep + "msg=" + url.QueryEscape(msg)
|
||||
if hasFrag {
|
||||
path += "#" + frag
|
||||
}
|
||||
}
|
||||
http.Redirect(w, r, path, http.StatusSeeOther)
|
||||
}
|
||||
|
||||
@@ -725,3 +725,17 @@ func TestSignalDiscoveryCard(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRedirectKeepsFragmentLast(t *testing.T) {
|
||||
for path, want := range map[string]string{
|
||||
"/signals#campaigns": "/signals?msg=saved#campaigns",
|
||||
"/prospects?status=new#x": "/prospects?status=new&msg=saved#x",
|
||||
"/signals": "/signals?msg=saved",
|
||||
} {
|
||||
w := httptest.NewRecorder()
|
||||
redirect(w, httptest.NewRequest("POST", path, nil), path, "saved")
|
||||
if got := w.Header().Get("Location"); got != want {
|
||||
t.Errorf("%s: got %q, want %q", path, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user