Skip to content

Commit 6069dc4

Browse files
committed
Fix rendering of float values
This was originally broken by the Encoder changes in 7073813 Resolves #11
1 parent d6a680f commit 6069dc4

2 files changed

Lines changed: 16 additions & 13 deletions

File tree

src/Runtime.php

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,9 @@ public static function isech(RuntimeContext $cx, mixed $v, mixed $in, \Closure $
248248
}
249249

250250
/**
251-
* HTML encode {{var}} just like handlebars.js
252-
*
253-
* @param array<array<mixed>|string|int>|string|SafeString|int|null $var value to be htmlencoded
251+
* HTML encode {{var}} just like Handlebars.js
254252
*/
255-
public static function encq($var): string
253+
public static function encq(mixed $var): string
256254
{
257255
if ($var instanceof SafeString) {
258256
return (string) $var;
@@ -263,23 +261,21 @@ public static function encq($var): string
263261

264262
/**
265263
* Get string representation for output
266-
*
267-
* @param array<mixed>|string|StringObject|int|bool|null $v value to be output
268264
*/
269-
public static function raw(array|string|StringObject|int|bool|null $v): string
265+
public static function raw(mixed $value): string
270266
{
271-
if ($v === true) {
267+
if ($value === true) {
272268
return 'true';
273269
}
274270

275-
if ($v === false) {
271+
if ($value === false) {
276272
return 'false';
277273
}
278274

279-
if (is_array($v)) {
280-
if (array_is_list($v)) {
275+
if (is_array($value)) {
276+
if (array_is_list($value)) {
281277
$ret = '';
282-
foreach ($v as $vv) {
278+
foreach ($value as $vv) {
283279
$ret .= static::raw($vv) . ',';
284280
}
285281
return substr($ret, 0, -1);
@@ -288,7 +284,7 @@ public static function raw(array|string|StringObject|int|bool|null $v): string
288284
}
289285
}
290286

291-
return "$v";
287+
return "$value";
292288
}
293289

294290
/**

tests/RegressionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,13 @@ public static function preventIndentProvider(): array
16791679
public static function rawProvider(): array
16801680
{
16811681
return [
1682+
[
1683+
'desc' => '#11 - floats are output as expected',
1684+
'template' => "{{{foo}}}",
1685+
'data' => ['foo' => 1.23],
1686+
'expected' => '1.23',
1687+
],
1688+
16821689
[
16831690
'desc' => 'LNC#66 - support {{&foo}} mustache raw syntax',
16841691
'template' => '{{&foo}} , {{foo}}, {{{foo}}}',

0 commit comments

Comments
 (0)