Skip to content

Commit

Permalink
Helpers::formatArgs() escaped \? means ? (possible BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Mar 14, 2017
1 parent 059135a commit 361f671
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/PhpGenerator/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,13 @@ public static function format($statement, ...$args)
*/
public static function formatArgs($statement, array $args)
{
$tokens = preg_split('#(\.\.\.\?|\$\?|->\?|::\?|\?\*|\?)#', $statement, -1, PREG_SPLIT_DELIM_CAPTURE);
$tokens = preg_split('#(\.\.\.\?|\$\?|->\?|::\?|\\\\\?|\?\*|\?)#', $statement, -1, PREG_SPLIT_DELIM_CAPTURE);
$res = '';
foreach ($tokens as $n => $token) {
if ($n % 2 === 0) {
$res .= $token;
} elseif ($token === '\\?') {
$res .= '?';
} elseif (!$args) {
throw new Nette\InvalidArgumentException('Insufficient number of arguments.');
} elseif ($token === '?') {
Expand Down
1 change: 1 addition & 0 deletions tests/PhpGenerator/Helpers.format.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Assert::same('func(1)', Helpers::format('func(?)', 1, 2));

Assert::same('func', Helpers::formatArgs('func', [1, 2]));
Assert::same('func(1)', Helpers::formatArgs('func(?)', [1, 2]));
Assert::same('func(1 ? 2 : 3)', Helpers::formatArgs('func(1 \? 2 : 3)', []));
Assert::same('func([1, 2])', Helpers::formatArgs('func(?)', [[1, 2]]));
Assert::same('func(1, 2)', Helpers::formatArgs('func(...?)', [[1, 2]]));
Assert::same('func(1, 2)', Helpers::formatArgs('func(?*)', [[1, 2]])); // old way
Expand Down

0 comments on commit 361f671

Please sign in to comment.