Skip to content

Commit 1d07213

Browse files
committed
Fix escaping multiple double quotes
zordius/lightncandy#298
1 parent ff199aa commit 1d07213

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/Parser.php

+8-9
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ protected static function getExpression(string $v, Context $context, int|string
7676

7777
// handle double-quoted string
7878
if (preg_match('/^"(.*)"$/', $v, $matched)) {
79-
return static::getLiteral(preg_replace('/([^\\\\])\\\\\\\\"/', '$1"', preg_replace('/^\\\\\\\\"/', '"', $matched[1])), $asis, true);
79+
$literal = str_replace('\\\\"', '"', $matched[1]);
80+
return static::getLiteral($literal, $asis, true);
8081
}
8182

8283
// handle single quoted string
@@ -150,18 +151,16 @@ protected static function getExpression(string $v, Context $context, int|string
150151
public static function parse(array $token, Context $context): array
151152
{
152153
$vars = static::analyze($token[Token::POS_INNERTAG], $context);
154+
$avars = static::advancedVariable($vars, $context, Token::toString($token));
155+
153156
if ($token[Token::POS_OP] === '>') {
154157
$fn = static::getPartialName($vars);
158+
if ($fn !== null) {
159+
$avars[0] = $fn;
160+
}
155161
} elseif ($token[Token::POS_OP] === '#*') {
156162
$fn = static::getPartialName($vars, 1);
157-
}
158-
159-
$avars = static::advancedVariable($vars, $context, Token::toString($token));
160-
161-
if (isset($fn)) {
162-
if ($token[Token::POS_OP] === '>') {
163-
$avars[0] = $fn;
164-
} elseif ($token[Token::POS_OP] === '#*') {
163+
if ($fn !== null) {
165164
$avars[1] = $fn;
166165
}
167166
}

tests/RegressionTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,19 @@ public static function issueProvider(): array
13331333
'expected' => 'foo " ',
13341334
],
13351335

1336+
[
1337+
'id' => 298,
1338+
'template' => '{{test "\"\"\"" prop="\"\"\""}}',
1339+
'options' => new Options(
1340+
helpers: [
1341+
'test' => function ($arg1, HelperOptions $options) {
1342+
return "{$arg1} {$options->hash['prop']}";
1343+
},
1344+
],
1345+
),
1346+
'expected' => '""" """',
1347+
],
1348+
13361349
[
13371350
'id' => 302,
13381351
'template' => "{{#*inline \"t1\"}}{{#if imageUrl}}<span />{{else}}<div />{{/if}}{{/inline}}{{#*inline \"t2\"}}{{#if imageUrl}}<span />{{else}}<div />{{/if}}{{/inline}}{{#*inline \"t3\"}}{{#if imageUrl}}<span />{{else}}<div />{{/if}}{{/inline}}",

0 commit comments

Comments
 (0)