@@ -121,43 +121,41 @@ func (r *Redirect) Route(name string, config ...RedirectConfig) error {
121
121
}
122
122
123
123
// Flash messages
124
- if len (r .messages ) > 0 {
124
+ if len (r .messages ) > 0 || len ( r . oldInput ) > 0 {
125
125
messageText := bytebufferpool .Get ()
126
126
defer bytebufferpool .Put (messageText )
127
127
128
+ // flash messages
128
129
i := 1
129
130
for k , v := range r .messages {
130
- _ , _ = messageText .WriteString ("k:" + k + ":" + v )
131
+ if i != 1 {
132
+ _ , _ = messageText .WriteString ("k:" )
133
+ }
134
+
135
+ _ , _ = messageText .WriteString (k + ":" + v )
131
136
if len (r .messages ) != i {
132
137
_ , _ = messageText .WriteString ("," )
133
138
}
134
139
i ++
135
140
}
136
141
137
- r .c .Cookie (& Cookie {
138
- Name : "fiber_flash" ,
139
- Value : r .c .app .getString (messageText .Bytes ()),
140
- SessionOnly : true ,
141
- })
142
- }
143
-
144
- // Old input data
145
- if len (r .oldInput ) > 0 {
146
- inputText := bytebufferpool .Get ()
147
- defer bytebufferpool .Put (inputText )
148
-
149
- i := 1
142
+ // old input data
143
+ i = 1
150
144
for k , v := range r .oldInput {
151
- _ , _ = inputText .WriteString ("k:" + k + ":" + v )
145
+ if i == 1 {
146
+ _ , _ = messageText .WriteString ("k:" )
147
+ }
148
+
149
+ _ , _ = messageText .WriteString ("k:old_input_data_" + k + ":" + v )
152
150
if len (r .oldInput ) != i {
153
- _ , _ = inputText .WriteString ("," )
151
+ _ , _ = messageText .WriteString ("," )
154
152
}
155
153
i ++
156
154
}
157
155
158
156
r .c .Cookie (& Cookie {
159
- Name : "fiber_flash_old_input " ,
160
- Value : r .c .app .getString (inputText .Bytes ()),
157
+ Name : "fiber_flash " ,
158
+ Value : r .c .app .getString (messageText .Bytes ()),
161
159
SessionOnly : true ,
162
160
})
163
161
}
@@ -198,28 +196,20 @@ func (r *Redirect) setFlash() {
198
196
// parse flash messages
199
197
if r .c .Cookies ("fiber_flash" ) != "" {
200
198
messages := strings .Split (r .c .Cookies ("fiber_flash" ), ",k:" )
201
- r .c .flashMessages = make (map [string ]string , len (messages ))
202
-
203
- for _ , msg := range messages {
204
- msg = strings .Replace (msg , "k:" , "" , 1 )
205
- splitMsg := strings .Split (msg , ":" )
206
-
207
- r .c .flashMessages [splitMsg [0 ]] = splitMsg [1 ]
208
- }
209
- }
210
-
211
- // parse old input data
212
- if r .c .Cookies ("fiber_flash_old_input" ) != "" {
213
- messages := strings .Split (r .c .Cookies ("fiber_flash_old_input" ), ",k:" )
214
- r .c .oldInput = make (map [string ]string , len (messages ))
199
+ r .c .flashMessages = make (map [string ]string )
200
+ r .c .oldInput = make (map [string ]string )
215
201
216
202
for _ , msg := range messages {
217
- msg = strings .Replace (msg , "k:" , "" , 1 )
218
203
splitMsg := strings .Split (msg , ":" )
219
204
220
- r .c .oldInput [splitMsg [0 ]] = splitMsg [1 ]
205
+ // check old input data
206
+ if strings .HasPrefix (msg , "old_input_data_" ) {
207
+ r .c .oldInput [splitMsg [0 ][15 :]] = splitMsg [1 ]
208
+ } else {
209
+ r .c .flashMessages [splitMsg [0 ]] = splitMsg [1 ]
210
+ }
221
211
}
222
212
}
223
213
224
- r .c .ClearCookie ("fiber_flash" , "fiber_flash_old_input" )
214
+ r .c .ClearCookie ("fiber_flash" )
225
215
}
0 commit comments