Skip to content

Commit

Permalink
utf8 key & value fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sroehrl committed Feb 13, 2022
1 parent ec42879 commit 759f96d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion TemplateFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ 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 {
Expand Down
11 changes: 6 additions & 5 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 @@ -172,9 +173,9 @@ public function testEvaluateTypedConditionNull()
public function testUtf8()
{
$array = ['one'=> 'über','keß'=>'plunder'];
$t = Template::embrace('<p n-if="one == \'über\'">show</p>', $array);
$t = Template::embraceFromFile('utf8.html', $array);
$this->assertStringContainsString('show', $t);
$t = Template::embrace('<p>{{keß}}</p>', $array);
$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 759f96d

Please sign in to comment.