Skip to content

Commit

Permalink
Merge pull request #11 from sroehrl/utf8
Browse files Browse the repository at this point in the history
Utf8
  • Loading branch information
sroehrl authored Feb 13, 2022
2 parents 70a37b5 + 759f96d commit ac73c3d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
6 changes: 3 additions & 3 deletions TemplateFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static function nFor($content, $array)
$extracted = self::extractAttribute($hit, 'n-for');
self::subContentGeneration($doc, $hit, $array, $extracted['parts'], $extracted['template']);
}
return $doc->saveHTML();
return utf8_decode($doc->saveHTML($doc->documentElement));
}

/**
Expand Down Expand Up @@ -251,13 +251,13 @@ static function nIf($content, $array)
$array = array_merge(self::$registeredClosures, $array);
foreach ($hits as $hit) {
$expression = $hit->getAttribute('n-if');
$bool = self::evaluateTypedCondition($array, $expression);
$bool = self::evaluateTypedCondition($array, utf8_decode($expression));
if (!$bool) {
$hit->parentNode->removeChild($hit);
} else {
$hit->removeAttribute('n-if');
}
}
return $doc->saveHTML();
return utf8_decode($doc->saveHTML($doc->documentElement));
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "neoan3-apps/template",
"description": "neoan3 minimal template engine",
"version": "1.1.1",
"version": "1.1.3",
"license": "MIT",
"autoload": {
"psr-4": {
Expand Down
15 changes: 12 additions & 3 deletions tests/TemplateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ public function testEmbrace()
public function testEmbraceSanitation()
{
$array = [
's/t' => 1, 's\t' => 1, 's+t' => 1, 's-t' => 1, 's{t' => 1
's/t' => 1, 's\t' => 2, 's+t' => 3, 's-t' => 4, 's{t' => 1
];
$template = '<p n-for="array as key => item">{{item}}</p>';
$res = '';
$template = '<div><p n-for="array as key => item">{{item}}</p></div>';
$res = '<div>';
foreach ($array as $item){
$res .= '<p>'. $item .'</p>';
}
$res .= '</div>';
$this->assertSame($res, trim(Template::embrace($template, ['array' =>$array])));
}

Expand Down Expand Up @@ -169,4 +170,12 @@ public function testEvaluateTypedConditionNull()
$t = Template::embrace('<p n-if="test === false">some</p>', $array);
$this->assertStringContainsString('p>some', $t);
}
public function testUtf8()
{
$array = ['one'=> 'über','keß'=>'plunder'];
$t = Template::embraceFromFile('utf8.html', $array);
$this->assertStringContainsString('show', $t);
$t = Template::embraceFromFile('utf8.html', $array);
$this->assertStringContainsString('plunder', $t);
}
}
2 changes: 2 additions & 0 deletions tests/utf8.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<div><p n-if="one === 'über'">show</p></div>
<div><p>{{keß}}</p></div>

0 comments on commit ac73c3d

Please sign in to comment.