From f8e765f83d4b1d2318d4811681a434f02fa30b4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torben=20K=C3=B6hn?= Date: Fri, 20 May 2016 12:03:38 +0200 Subject: [PATCH] Hopefully fixed (#88) --- Compiler.php | 5 +++++ Lexer.php | 12 +++++------- Test/IssueTest.php | 9 +++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Compiler.php b/Compiler.php index 7ba6de7..42886e9 100644 --- a/Compiler.php +++ b/Compiler.php @@ -1864,6 +1864,10 @@ protected function compileChildren(array $nodes, $indent = true, $allowInline = foreach ($nodes as $idx => $node) { + // Skip empty text lines completely + if ($node->type === 'text' && trim($node->value) === '') + continue; + $phtml .= $this->newLine().$this->indent().$this->compileNode($node); } $this->level -= $indent ? 1 : 0; @@ -2108,6 +2112,7 @@ protected function compileElement(Node $node) protected function compileText(Node $node) { + //Dont print empty text if ($node->escaped) $text = $this->createShortCode( 'htmlentities('.$this->exportScalar($node->value, '\'', true).', \\ENT_QUOTES, \''.$this->options['escape_charset'].'\')' diff --git a/Lexer.php b/Lexer.php index c0b882f..9bcc195 100644 --- a/Lexer.php +++ b/Lexer.php @@ -359,8 +359,8 @@ public function lex($input) { $this->input = rtrim(str_replace([ - "\r", "\0" - ], '', $input))."\n"; + "\r", "\0" + ], '', $input))."\n"; $this->length = $this->strlen($this->input); $this->position = 0; @@ -941,18 +941,16 @@ protected function scanNewLine() * Scans for text until the end of the current line * and yields a -token if found. * + * @param bool $escaped * @return \Generator */ protected function scanText($escaped = false) { - foreach ($this->scanToken('text', "([^\n]*)") as $token) { + foreach ($this->scanToken('text', "([^\n]*)?") as $token) { $value = trim($this->getMatch(1)); - if ($value === '') - continue; - $token['value'] = $value; $token['escaped'] = $escaped; yield $token; @@ -1129,7 +1127,7 @@ protected function scanBlock() foreach ($this->scanToken( 'block', - 'block((?:[\t ]+(?append|prepend|replace))?(?:[\t ]+(?[a-zA-Z_][a-zA-Z0-9\-_]*))|[\t \n])' + 'block((?:[\t ]+(?append|prepend|replace))?(?:[\t ]+(?[a-zA-Z_][a-zA-Z0-9\-_]*))|[\t ]*\n)' ) as $token) { yield $token; diff --git a/Test/IssueTest.php b/Test/IssueTest.php index 09df837..cf2ae15 100644 --- a/Test/IssueTest.php +++ b/Test/IssueTest.php @@ -134,4 +134,13 @@ public function testIssue95() $this->assertEquals('
', $this->renderer->compile('blockquote')); } + + public function testIssue88() + { + + $this->assertEquals('', $this->renderer->compile("some-tag \nsome-other-tag")); + $this->assertEquals('', $this->renderer->compile("some-tag\t\nsome-other-tag")); + $this->assertEquals('', $this->renderer->compile("some-tag \nsome-other-tag")); + $this->assertEquals('', $this->renderer->compile("some-tag \t \nsome-other-tag")); + } } \ No newline at end of file