diff --git a/src/Fenom/Compiler.php b/src/Fenom/Compiler.php index 04d0998..0edaf22 100644 --- a/src/Fenom/Compiler.php +++ b/src/Fenom/Compiler.php @@ -402,7 +402,7 @@ class Compiler $tag["last"][] = false; $tokens->next(); } else { - $tag["last"][] = $tag->tpl->parseScalar($tokens, false); + $tag["last"][] = $tag->tpl->parseScalar($tokens); } if ($tokens->is(',')) { $tokens->next(); diff --git a/src/Fenom/Template.php b/src/Fenom/Template.php index b18774e..9ea3a2e 100644 --- a/src/Fenom/Template.php +++ b/src/Fenom/Template.php @@ -330,6 +330,7 @@ class Template extends Render private function _appendText($text) { $this->_line += substr_count($text, "\n"); + $strip = $this->_options & Fenom::AUTO_STRIP; if ($this->_filters) { if (strpos($text, "_filters as $filter) { @@ -344,13 +345,12 @@ class Template extends Render } } } - $text = implode('', $fragments); + $text = implode('' . ($strip ? '' : PHP_EOL), $fragments); } } else { - $text = str_replace("' . PHP_EOL, $text); + $text = str_replace("' . ($strip ? '' : PHP_EOL), $text); } - if($this->_options & Fenom::AUTO_STRIP) { - + if($strip) { $text = preg_replace('/\s+/uS', ' ', str_replace(array("\r", "\n"), " ", $text)); $text = str_replace("> <", "><", $text); } @@ -563,6 +563,8 @@ class Template extends Render throw new SecurityException($e->getMessage() . " in {$this->_name} line {$this->_line}, near '{" . $tokens->getSnippetAsString(0, 0) . "' <- there", 0, E_ERROR, $this->_name, $this->_line, $e); } catch (\Exception $e) { throw new CompileException($e->getMessage() . " in {$this->_name} line {$this->_line}, near '{" . $tokens->getSnippetAsString(0, 0) . "' <- there", 0, E_ERROR, $this->_name, $this->_line, $e); + } catch (\Throwable $e) { + throw new CompileException($e->getMessage() . " in {$this->_name} line {$this->_line}, near '{" . $tokens->getSnippetAsString(0, 0) . "' <- there", 0, E_ERROR, $this->_name, $this->_line, $e); } } @@ -718,7 +720,7 @@ class Template extends Render $exp[] = $this->parseIs($tokens, $item, $var); } elseif ($operator == "in" || ($operator == "not" && $tokens->isNextToken("in"))) { $item = array_pop($exp); - $exp[] = $this->parseIn($tokens, $item, $var); + $exp[] = $this->parseIn($tokens, $item); } else { break; } @@ -785,7 +787,7 @@ class Template extends Render switch($tokens->key()) { case T_LNUMBER: case T_DNUMBER: - $code = $unary . $this->parseScalar($tokens, true); + $code = $unary . $this->parseScalar($tokens); break; case T_CONSTANT_ENCAPSED_STRING: case '"': @@ -793,7 +795,7 @@ class Template extends Render if ($unary) { throw new UnexpectedTokenException($tokens->back()); } - $code = $this->parseScalar($tokens, true); + $code = $this->parseScalar($tokens); break; case '$': $code = $this->parseAccessor($tokens, $is_var); diff --git a/tests/cases/FenomTest.php b/tests/cases/FenomTest.php index 17e0605..d6f1f6b 100644 --- a/tests/cases/FenomTest.php +++ b/tests/cases/FenomTest.php @@ -349,6 +349,18 @@ class FenomTest extends \Fenom\TestCase TPL; $this->assertRender($tpl, '
number one
'); } + + /** + * Bug #195 + * @group strip-xml + */ + public function testStripXML() { + $this->fenom->setOptions(Fenom::AUTO_STRIP); + $tpl = << +TPL; + $this->assertRender($tpl, ''); + } }