Skip to content

Commit

Permalink
Lists listener - check for type being an array (#53)
Browse files Browse the repository at this point in the history
* Check for array

* Create Issue53Test.php

* Update Issue53Test.php

Co-authored-by: Basil <[email protected]>
  • Loading branch information
Blitheness and nadar authored Oct 27, 2021
1 parent a9dbe7b commit f269b82
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/listener/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ public function render(Lexer $lexer)
*/
protected function getListAttribute(Pick $pick)
{
if ($pick->type == self::LIST_TYPE_ORDERED) {
$type = is_array($pick->type) ? $pick->type['type'] : $pick->type;

if ($type === self::LIST_TYPE_ORDERED) {
return 'ol';
}

if ($pick->type == self::LIST_TYPE_BULLET) {
if ($type === self::LIST_TYPE_BULLET) {
return 'ul';
}

// prevent html injection in case the attribute is user input
throw new Exception('The provided list type "'.$pick->type.'" is not a known list type (ordered or bullet).');
throw new Exception('The provided list type "'.$type.'" is not a known list type (ordered or bullet).');
}
}
25 changes: 25 additions & 0 deletions tests/Issue53Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace nadar\quill\tests;

class Issue53Test extends DeltaTestCase
{
public $json = <<<'JSON'
{"ops":[{
"attributes": {
"list": {
"depth": 0,
"type": "bullet"
}
},
"insert": "\n"
},
{
"insert": "Bullet point content"
}
]}
JSON;

public $html = <<<'EOT'
<ul><li>Bullet point content</li></ul>
EOT;
}

0 comments on commit f269b82

Please sign in to comment.