Skip to content

Commit 00c00f4

Browse files
committed
empty property name bug
1 parent 21e98d9 commit 00c00f4

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Schema.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,10 @@ private function process($data, $import = true, DataPreProcessor $preProcessor =
303303
$this->fail(new ObjectException("Too many properties", ObjectException::TOO_MANY), $path);
304304
}
305305
foreach ($array as $key => $value) {
306+
if ($key === '' && PHP_VERSION_ID < 71000) {
307+
$this->fail(new InvalidValue('Empty property name'), $path);
308+
}
309+
306310
$found = false;
307311
if (isset($this->dependencies[$key])) {
308312
$dependencies = $this->dependencies[$key];

tests/src/PHPUnit/Constraint/AdditionalItemsTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55

66
use Swaggest\JsonSchema\InvalidValue;
7+
use Swaggest\JsonSchema\Schema;
78
use Swaggest\JsonSchema\SchemaLoader;
89

910
class AdditionalItemsTest extends \PHPUnit_Framework_TestCase
@@ -25,4 +26,18 @@ public function testAdditionalItemsAreNotAllowed()
2526
$schema->import(array(1,2,3,4));
2627
}
2728

29+
public function testEmptyPropertyName()
30+
{
31+
$schema = new Schema();
32+
$schema->additionalProperties = Schema::integer();
33+
34+
if (PHP_VERSION_ID < 71000) {
35+
$this->setExpectedException(get_class(new InvalidValue()), 'Empty property name');
36+
}
37+
38+
$data = (object)array('' => 1, 'a' => 2, 1 => 3);
39+
$schema->import($data);
40+
$schema->export($data);
41+
}
42+
2843
}

0 commit comments

Comments
 (0)