Skip to content

Commit 361f671

Browse files
committed
Helpers::formatArgs() escaped \? means ? (possible BC break)
1 parent 059135a commit 361f671

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/PhpGenerator/Helpers.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,13 @@ public static function format($statement, ...$args)
165165
*/
166166
public static function formatArgs($statement, array $args)
167167
{
168-
$tokens = preg_split('#(\.\.\.\?|\$\?|->\?|::\?|\?\*|\?)#', $statement, -1, PREG_SPLIT_DELIM_CAPTURE);
168+
$tokens = preg_split('#(\.\.\.\?|\$\?|->\?|::\?|\\\\\?|\?\*|\?)#', $statement, -1, PREG_SPLIT_DELIM_CAPTURE);
169169
$res = '';
170170
foreach ($tokens as $n => $token) {
171171
if ($n % 2 === 0) {
172172
$res .= $token;
173+
} elseif ($token === '\\?') {
174+
$res .= '?';
173175
} elseif (!$args) {
174176
throw new Nette\InvalidArgumentException('Insufficient number of arguments.');
175177
} elseif ($token === '?') {

tests/PhpGenerator/Helpers.format.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Assert::same('func(1)', Helpers::format('func(?)', 1, 2));
1616

1717
Assert::same('func', Helpers::formatArgs('func', [1, 2]));
1818
Assert::same('func(1)', Helpers::formatArgs('func(?)', [1, 2]));
19+
Assert::same('func(1 ? 2 : 3)', Helpers::formatArgs('func(1 \? 2 : 3)', []));
1920
Assert::same('func([1, 2])', Helpers::formatArgs('func(?)', [[1, 2]]));
2021
Assert::same('func(1, 2)', Helpers::formatArgs('func(...?)', [[1, 2]]));
2122
Assert::same('func(1, 2)', Helpers::formatArgs('func(?*)', [[1, 2]])); // old way

0 commit comments

Comments
 (0)