@@ -185,50 +185,56 @@ func (v *Validation) Check(obj interface{}, checks ...Validator) *ValidationResu
185
185
186
186
// ValidationFilter revel Filter function to be hooked into the filter chain.
187
187
func ValidationFilter (c * Controller , fc []Filter ) {
188
- errors , err := restoreValidationErrors (c .Request )
189
- c .Validation = & Validation {
190
- Errors : errors ,
191
- keep : false ,
192
- }
193
- hasCookie := (err != http .ErrNoCookie )
194
-
195
- fc [0 ](c , fc [1 :])
196
-
197
- // Add Validation errors to ViewArgs.
198
- c .ViewArgs ["errors" ] = c .Validation .ErrorMap ()
199
-
200
- // Store the Validation errors
201
- var errorsValue string
202
- if c .Validation .keep {
203
- for _ , error := range c .Validation .Errors {
204
- if error .Message != "" {
205
- errorsValue += "\x00 " + error .Key + ":" + error .Message + "\x00 "
206
- }
207
- }
208
- }
209
-
210
- // When there are errors from Validation and Keep() has been called, store the
211
- // values in a cookie. If there previously was a cookie but no errors, remove
212
- // the cookie.
213
- if errorsValue != "" {
214
- c .SetCookie (& http.Cookie {
215
- Name : CookiePrefix + "_ERRORS" ,
216
- Value : url .QueryEscape (errorsValue ),
217
- Domain : CookieDomain ,
218
- Path : "/" ,
219
- HttpOnly : true ,
220
- Secure : CookieSecure ,
221
- })
222
- } else if hasCookie {
223
- c .SetCookie (& http.Cookie {
224
- Name : CookiePrefix + "_ERRORS" ,
225
- MaxAge : - 1 ,
226
- Domain : CookieDomain ,
227
- Path : "/" ,
228
- HttpOnly : true ,
229
- Secure : CookieSecure ,
230
- })
231
- }
188
+ // Ignore cookies on json requests
189
+ if c .Params != nil && c .Params .JsonRequest {
190
+ c .Validation = & Validation {}
191
+ fc [0 ](c , fc [1 :])
192
+ } else {
193
+ errors , err := restoreValidationErrors (c .Request )
194
+ c .Validation = & Validation {
195
+ Errors : errors ,
196
+ keep : false ,
197
+ }
198
+ hasCookie := (err != http .ErrNoCookie )
199
+
200
+ fc [0 ](c , fc [1 :])
201
+
202
+ // Add Validation errors to ViewArgs.
203
+ c .ViewArgs ["errors" ] = c .Validation .ErrorMap ()
204
+
205
+ // Store the Validation errors
206
+ var errorsValue string
207
+ if c .Validation .keep {
208
+ for _ , error := range c .Validation .Errors {
209
+ if error .Message != "" {
210
+ errorsValue += "\x00 " + error .Key + ":" + error .Message + "\x00 "
211
+ }
212
+ }
213
+ }
214
+
215
+ // When there are errors from Validation and Keep() has been called, store the
216
+ // values in a cookie. If there previously was a cookie but no errors, remove
217
+ // the cookie.
218
+ if errorsValue != "" {
219
+ c .SetCookie (& http.Cookie {
220
+ Name : CookiePrefix + "_ERRORS" ,
221
+ Value : url .QueryEscape (errorsValue ),
222
+ Domain : CookieDomain ,
223
+ Path : "/" ,
224
+ HttpOnly : true ,
225
+ Secure : CookieSecure ,
226
+ })
227
+ } else if hasCookie {
228
+ c .SetCookie (& http.Cookie {
229
+ Name : CookiePrefix + "_ERRORS" ,
230
+ MaxAge : - 1 ,
231
+ Domain : CookieDomain ,
232
+ Path : "/" ,
233
+ HttpOnly : true ,
234
+ Secure : CookieSecure ,
235
+ })
236
+ }
237
+ }
232
238
}
233
239
234
240
// Restore Validation.Errors from a request.
0 commit comments