mirror of
https://github.com/justinrainbow/json-schema.git
synced 2025-05-04 05:18:02 +02:00
Fix issues with uniqueItems in arrays. Use var_export() instead of print_r().
This commit is contained in:
parent
e09aa0b7a3
commit
c230cad5f2
@ -36,7 +36,7 @@ class Collection extends Constraint
|
||||
if (isset($schema->uniqueItems)) {
|
||||
$unique = $value;
|
||||
if (is_array($value) && count($value)) {
|
||||
$unique = array_map(function($e) { return print_r($e, true); }, $value);
|
||||
$unique = array_map(function($e) { return var_export($e, true); }, $value);
|
||||
}
|
||||
if (count(array_unique($unique)) != count($value)) {
|
||||
$this->addError($path, "There are no duplicates allowed in the array");
|
||||
|
@ -34,6 +34,27 @@ class UniqueItemsTest extends BaseTestCase
|
||||
"type": "array",
|
||||
"uniqueItems": true
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'[1.0, 1.00, 1]',
|
||||
'{
|
||||
"type": "array",
|
||||
"uniqueItems": true
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'[["foo"], ["foo"]]',
|
||||
'{
|
||||
"type": "array",
|
||||
"uniqueItems": true
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'[{}, [1], true, null, {}, 1]',
|
||||
'{
|
||||
"type": "array",
|
||||
"uniqueItems": true
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
@ -54,6 +75,41 @@ class UniqueItemsTest extends BaseTestCase
|
||||
"type": "array",
|
||||
"uniqueItems": true
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'[1, true]',
|
||||
'{
|
||||
"type": "array",
|
||||
"uniqueItems": true
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'[0, false]',
|
||||
'{
|
||||
"type": "array",
|
||||
"uniqueItems": true
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : false}}}]',
|
||||
'{
|
||||
"type": "array",
|
||||
"uniqueItems": true
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'[["foo"], ["bar"]]',
|
||||
'{
|
||||
"type": "array",
|
||||
"uniqueItems": true
|
||||
}'
|
||||
),
|
||||
array(
|
||||
'[{}, [1], true, null, 1]',
|
||||
'{
|
||||
"type": "array",
|
||||
"uniqueItems": true
|
||||
}'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user