Commit 34761d8 1 parent 61ecdd9 commit 34761d8 Copy full SHA for 34761d8
File tree 2 files changed +34
-2
lines changed
2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 6
6
7
7
class StoreUserRequest extends FormRequest
8
8
{
9
+ /**
10
+ * Sanitize before rules()
11
+ */
12
+ protected function sanitizeInput ()
13
+ {
14
+ $ input = $ this ->all ();
15
+ $ input ['name ' ] = preg_replace ("~[\p{M}]~uis " , "" , $ this ->input ('name ' ));
16
+ $ this ->replace ($ input );
17
+ }
18
+
9
19
/**
10
20
* Get the validation rules that apply to the request.
11
21
*
@@ -17,7 +27,7 @@ public function rules()
17
27
'name ' => 'required|string|min:1|max:150 ' ,
18
28
'email ' => 'required|email:rfc,dns ' ,
19
29
'password ' => 'required|string|min:8|max:128 ' ,
20
- 'role ' => 'required|string|min:1|max:150 ' ,
30
+ 'role ' => 'required|string|min:1|max:150|regex:/^[a-zA-Z]+$/ ' , // Regex for ASCII letters
21
31
];
22
32
}
23
33
@@ -28,6 +38,8 @@ public function rules()
28
38
*/
29
39
protected function getValidatorInstance ()
30
40
{
41
+ $ this ->sanitizeInput ();
42
+
31
43
return parent ::getValidatorInstance ()->after (function () {
32
44
// Check if password and confirm password match
33
45
if ($ this ->input ('password ' ) != $ this ->input ('confirm_password ' )) {
Original file line number Diff line number Diff line change 6
6
7
7
class UpdateUserRequest extends FormRequest
8
8
{
9
+ /**
10
+ * Sanitize before rules()
11
+ */
12
+ protected function sanitizeInput ()
13
+ {
14
+ $ input = $ this ->all ();
15
+ $ input ['name ' ] = preg_replace ("~[\p{M}]~uis " , "" , $ this ->input ('name ' ));
16
+ $ this ->replace ($ input );
17
+ }
18
+
9
19
/**
10
20
* Get the validation rules that apply to the request.
11
21
*
@@ -17,7 +27,17 @@ public function rules()
17
27
'name ' => 'required|string|min:1|max:150 ' ,
18
28
'email ' => 'email:rfc,dns ' ,
19
29
'password ' => 'string|min:8|max:128 ' ,
20
- 'role ' => 'string|min:1|max:150 ' ,
30
+ 'role ' => 'string|min:1|max:150|regex:/^[a-zA-Z]+$/ ' , // Regex for ASCII letters
21
31
];
22
32
}
33
+
34
+ /**
35
+ * Validate request
36
+ *
37
+ * @return Illuminate\Foundation\Http\FormRequest::getValidatorInstance
38
+ */
39
+ protected function getValidatorInstance ()
40
+ {
41
+ $ this ->sanitizeInput ();
42
+ }
23
43
}
You can’t perform that action at this time.
0 commit comments