Skip to content

Commit 79eac4b

Browse files
committed
fix for nested objects
1 parent 37a4fc8 commit 79eac4b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

json-validator.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,23 @@ function is_valid_mf2_object($input) {
5353

5454
// If a value of a property is not a string, it must be a valid mf2 object
5555
foreach($property as $k=>$val) {
56-
// e-* get parsed as objects
5756
if(is_object($val)) {
58-
if(!property_exists($val, 'value'))
59-
return [false, 'Object '.$k.' is missing the "value" property'];
57+
// Try to detect e- parsed objects
58+
if(property_exists($val, 'value') && !property_exists($val, 'html'))
59+
return [false, 'One of the values of '.$key.' is missing the "html" property'];
60+
61+
if(property_exists($val, 'html') && !property_exists($val, 'value'))
62+
return [false, 'One of the values of '.$key.' is missing the "value" property'];
63+
64+
// Otherwise this must be a nested object
65+
list($valid, $error) = is_valid_mf2_object($val);
66+
if(!$valid)
67+
return [false, 'One of the values of "'.$key.'" is not a valid mf2 object: '.$error];
6068

61-
if(!property_exists($val, 'html'))
62-
return [false, 'Object '.$k.' is missing the "html" property'];
6369
} else if(!is_string($val)) {
6470
if(is_numeric($val))
6571
return [false, 'One of the values of "'.$key.'" is a number instead of a string'];
72+
6673
list($valid, $error) = is_valid_mf2_object($val);
6774
if($error)
6875
return [false, 'One of the values of "'.$key.'" is not a valid mf2 object'];

0 commit comments

Comments
 (0)