Skip to content

Commit 6d0d6f1

Browse files
authored
Merge pull request #26 from codex-editor/fix-array
Fix undefined key
2 parents 021b586 + 38bcdbe commit 6d0d6f1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

EditorJS/BlockHandler.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,15 @@ private function sanitize($rules, $blockData)
189189
* Sanitize every key in data block
190190
*/
191191
foreach ($blockData as $key => $value) {
192-
$rule = $rules[$key];
192+
/**
193+
* PHP Array has integer keys
194+
*/
195+
if (is_integer($key)) {
196+
$rule = $rules[BlockHandler::DEFAULT_ARRAY_KEY];
197+
} else {
198+
$rule = $rules[$key];
199+
}
200+
193201
$elementType = $rule['type'];
194202

195203
/**

tests/BlockHandlerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,16 @@ public function testCanBeOnly()
5959

6060
$this->assertException($callable, EditorJSException::class, null, 'Option \'level\' with value `5` has invalid value. Check canBeOnly param.');
6161
}
62+
63+
public function testListTool()
64+
{
65+
$data = '{"time":1539180803359,"blocks":[{"type":"list","data":{"style":"ordered","items":["first","second","third"]}}],"version":"2.1.1"}';
66+
$editor = new EditorJS($data, $this->configuration);
67+
$result = $editor->getBlocks();
68+
69+
$this->assertEquals(3, count($result[0]['data']['items']));
70+
$this->assertEquals("first", $result[0]['data']['items'][0]);
71+
$this->assertEquals("second", $result[0]['data']['items'][1]);
72+
$this->assertEquals("third", $result[0]['data']['items'][2]);
73+
}
6274
}

0 commit comments

Comments
 (0)