Skip to content

Commit b70c9c2

Browse files
committed
Fix parsing hash options with line breaks
zordius/lightncandy#310
1 parent e179b29 commit b70c9c2

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ protected static function advancedVariable(array $vars, Context $context, string
239239
continue;
240240
}
241241

242-
if (preg_match('/^((\\[([^\\]]+)\\])|([^=^\\["\']+))=(.+)$/', $var, $m)) {
243-
$idx = $m[3] ? $m[3] : $m[4];
242+
if (preg_match('/^((\\[([^\\]]+)\\])|([^=^\\["\']+))=(.+)$/s', $var, $m)) {
243+
$idx = $m[3] ?: $m[4];
244244
$var = $m[5];
245245
// handle foo=(...)
246246
if (preg_match(SafeString::IS_SUBEXP_SEARCH, $var)) {

tests/RegressionTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,6 +1311,27 @@ public static function issueProvider(): array
13111311
'expected' => '',
13121312
],
13131313

1314+
[
1315+
'id' => 310,
1316+
'template' => <<<_tpl
1317+
{{#custom-block 'some-text' data=(custom-helper
1318+
opt_a='foo'
1319+
opt_b='bar'
1320+
)}}...{{/custom-block}}
1321+
_tpl,
1322+
'options' => new Options(
1323+
helpers: [
1324+
'custom-block' => function ($string, HelperOptions $opts) {
1325+
return strtoupper($string) . '-' . $opts->hash['data'] . $opts->fn();
1326+
},
1327+
'custom-helper' => function (HelperOptions $options) {
1328+
return $options->hash['opt_a'] . $options->hash['opt_b'];
1329+
},
1330+
],
1331+
),
1332+
'expected' => 'SOME-TEXT-foobar...',
1333+
],
1334+
13141335
[
13151336
'id' => 315,
13161337
'template' => '{{#each foo}}#{{@key}}({{@index}})={{.}}-{{moo}}-{{@irr}}{{/each}}',

0 commit comments

Comments
 (0)