@@ -35,7 +35,7 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i =
35
35
36
36
switch ($ schema ->format ) {
37
37
case 'date ' :
38
- if (!$ date = $ this ->validateDateTime ($ element , 'Y-m-d ' )) {
38
+ if (is_string ( $ element ) && !$ date = $ this ->validateDateTime ($ element , 'Y-m-d ' )) {
39
39
$ this ->addError (ConstraintError::FORMAT_DATE (), $ path , [
40
40
'date ' => $ element ,
41
41
'format ' => $ schema ->format
@@ -45,7 +45,7 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i =
45
45
break ;
46
46
47
47
case 'time ' :
48
- if (!$ this ->validateDateTime ($ element , 'H:i:s ' )) {
48
+ if (is_string ( $ element ) && !$ this ->validateDateTime ($ element , 'H:i:s ' )) {
49
49
$ this ->addError (ConstraintError::FORMAT_TIME (), $ path , [
50
50
'time ' => json_encode ($ element ),
51
51
'format ' => $ schema ->format ,
@@ -55,7 +55,7 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i =
55
55
break ;
56
56
57
57
case 'date-time ' :
58
- if (null === Rfc3339::createFromString ($ element )) {
58
+ if (is_string ( $ element ) && null === Rfc3339::createFromString ($ element )) {
59
59
$ this ->addError (ConstraintError::FORMAT_DATE_TIME (), $ path , [
60
60
'dateTime ' => json_encode ($ element ),
61
61
'format ' => $ schema ->format
@@ -101,14 +101,14 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i =
101
101
break ;
102
102
103
103
case 'uri ' :
104
- if (null === filter_var ($ element , FILTER_VALIDATE_URL , FILTER_NULL_ON_FAILURE )) {
104
+ if (is_string ( $ element ) && null === filter_var ($ element , FILTER_VALIDATE_URL , FILTER_NULL_ON_FAILURE )) {
105
105
$ this ->addError (ConstraintError::FORMAT_URL (), $ path , ['format ' => $ schema ->format ]);
106
106
}
107
107
break ;
108
108
109
109
case 'uriref ' :
110
110
case 'uri-reference ' :
111
- if (null === filter_var ($ element , FILTER_VALIDATE_URL , FILTER_NULL_ON_FAILURE )) {
111
+ if (is_string ( $ element ) && null === filter_var ($ element , FILTER_VALIDATE_URL , FILTER_NULL_ON_FAILURE )) {
112
112
// FILTER_VALIDATE_URL does not conform to RFC-3986, and cannot handle relative URLs, but
113
113
// the json-schema spec uses RFC-3986, so need a bit of hackery to properly validate them.
114
114
// See https://tools.ietf.org/html/rfc3986#section-4.2 for additional information.
@@ -133,6 +133,9 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i =
133
133
break ;
134
134
135
135
case 'email ' :
136
+ if (!is_string ($ element )) {
137
+ break ;
138
+ }
136
139
$ filterFlags = FILTER_NULL_ON_FAILURE ;
137
140
if (defined ('FILTER_FLAG_EMAIL_UNICODE ' )) {
138
141
// Only available from PHP >= 7.1.0, so ignore it for coverage checks
@@ -145,13 +148,13 @@ public function check(&$element, $schema = null, ?JsonPointer $path = null, $i =
145
148
146
149
case 'ip-address ' :
147
150
case 'ipv4 ' :
148
- if (null === filter_var ($ element , FILTER_VALIDATE_IP , FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV4 )) {
151
+ if (is_string ( $ element ) && null === filter_var ($ element , FILTER_VALIDATE_IP , FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV4 )) {
149
152
$ this ->addError (ConstraintError::FORMAT_IP (), $ path , ['format ' => $ schema ->format ]);
150
153
}
151
154
break ;
152
155
153
156
case 'ipv6 ' :
154
- if (null === filter_var ($ element , FILTER_VALIDATE_IP , FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV6 )) {
157
+ if (is_string ( $ element ) && null === filter_var ($ element , FILTER_VALIDATE_IP , FILTER_NULL_ON_FAILURE | FILTER_FLAG_IPV6 )) {
155
158
$ this ->addError (ConstraintError::FORMAT_IP (), $ path , ['format ' => $ schema ->format ]);
156
159
}
157
160
break ;
@@ -191,11 +194,19 @@ protected function validateDateTime($datetime, $format)
191
194
192
195
protected function validateRegex ($ regex )
193
196
{
197
+ if (!is_string ($ regex )) {
198
+ return true ;
199
+ }
200
+
194
201
return false !== @preg_match (self ::jsonPatternToPhpRegex ($ regex ), '' );
195
202
}
196
203
197
204
protected function validateColor ($ color )
198
205
{
206
+ if (!is_string ($ color )) {
207
+ return true ;
208
+ }
209
+
199
210
if (in_array (strtolower ($ color ), ['aqua ' , 'black ' , 'blue ' , 'fuchsia ' ,
200
211
'gray ' , 'green ' , 'lime ' , 'maroon ' , 'navy ' , 'olive ' , 'orange ' , 'purple ' ,
201
212
'red ' , 'silver ' , 'teal ' , 'white ' , 'yellow ' ])) {
@@ -220,6 +231,10 @@ protected function validatePhone($phone)
220
231
221
232
protected function validateHostname ($ host )
222
233
{
234
+ if (!is_string ($ host )) {
235
+ return true ;
236
+ }
237
+
223
238
$ hostnameRegex = '/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/i ' ;
224
239
225
240
return preg_match ($ hostnameRegex , $ host );
0 commit comments