Skip to content

Commit 5a4d8eb

Browse files
jrfnlgrogy
authored andcommitted
SyntaxError::translateTokens(): prevent double translation
Generally speaking, the `$translate` parameter for the `SyntaxError::getNormalizedMessage()` method should only be passed as `true` when on a PHP version which doesn't do the PHP native token translation yet. However, in edge cases, it could be possible that tokens could be double "translated", both by PHP itself as well as by the `SyntaxError::translateTokens()` method. This minor fix prevents this by not matching token names when surrounded by parentheses.
1 parent da3ea49 commit 5a4d8eb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Error.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ protected function translateTokens($message)
194194
'T_ECHO' => 'echo'
195195
);
196196

197-
return preg_replace_callback('~T_([A-Z_]*)~', function ($matches) use ($translateTokens) {
197+
return preg_replace_callback('~(?<!\()T_([A-Z_]*)(?!\))~', function ($matches) use ($translateTokens) {
198198
list($tokenName) = $matches;
199199
if (isset($translateTokens[$tokenName])) {
200200
$operator = $translateTokens[$tokenName];

0 commit comments

Comments
 (0)