Skip to content

Commit

Permalink
Fix PHP fatal error when maximumNestingLevel was reached.
Browse files Browse the repository at this point in the history
close #98
  • Loading branch information
tanakahisateru authored and cebe committed Mar 6, 2015
1 parent 9d6c36d commit f681fee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ protected function parseInline($text)
{
if ($this->_depth >= $this->maximumNestingLevel) {
// maximum depth is reached, do not parse input
return ['text', $text];
return [['text', $text]];
}
$this->_depth++;

Expand Down
22 changes: 22 additions & 0 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ public function testMarkerOrder()
$this->assertEquals('Result is A', $parser->parseParagraph('Result is [abc]'));
$this->assertEquals('Result is B', $parser->parseParagraph('Result is [[abc]]'));
}

public function testMaxNestingLevel()
{
$parser = new TestParser();
$parser->markers = [
'[' => 'parseMarkerC',
];

$parser->maximumNestingLevel = 3;
$this->assertEquals("(C-a(C-b(C-c)))", $parser->parseParagraph('[a[b[c]]]'));
$parser->maximumNestingLevel = 2;
$this->assertEquals("(C-a(C-b[c]))", $parser->parseParagraph('[a[b[c]]]'));
$parser->maximumNestingLevel = 1;
$this->assertEquals("(C-a[b[c]])", $parser->parseParagraph('[a[b[c]]]'));
}
}

class TestParser extends Parser
Expand All @@ -61,4 +76,11 @@ protected function parseMarkerB($text)
{
return [['text', 'B'], strrpos($text, ']') + 1];
}

protected function parseMarkerC($text)
{
$terminatingMarkerPos = strrpos($text, ']');
$inside = $this->parseInline(substr($text, 1, $terminatingMarkerPos - 1));
return [['text', '(C-' . $this->renderAbsy($inside) . ')'], $terminatingMarkerPos + 1];
}
}

0 comments on commit f681fee

Please sign in to comment.