Fix parsing function call arguments when arg strings contain commas

This commit is contained in:
Tautvidas Sipavičius
2016-12-14 17:32:19 +02:00
parent 61ab583030
commit f4b7acca1e
4 changed files with 12 additions and 15 deletions

View File

@ -99,15 +99,8 @@ class RoboFile extends \Robo\Tasks {
function makepot() { function makepot() {
return $this->_exec('./node_modules/.bin/grunt makepot'. return $this->_exec('./node_modules/.bin/grunt makepot'.
' --gruntfile '.__DIR__.'/tasks/makepot/makepot.js'. ' --gruntfile='.__DIR__.'/tasks/makepot/makepot.js'.
' --base_path '.__DIR__ ' --base_path='.__DIR__
);
}
function pushpot() {
return $this->_exec('./node_modules/.bin/grunt pushpot'.
' --gruntfile '.__DIR__.'/tasks/makepot/makepot.js'.
' --base_path '.__DIR__
); );
} }

View File

@ -23,10 +23,13 @@ module.exports = function (grunt) {
cwd: '.', // base path where to look for translatable strings cwd: '.', // base path where to look for translatable strings
domainPath: 'lang', // where to save the .pot domainPath: 'lang', // where to save the .pot
exclude: [ exclude: [
'build/.*', 'assets/.*',
'lang/.*',
'node_modules/.*',
'plugin_repository/.*',
'tasks/.*',
'tests/.*', 'tests/.*',
'vendor/.*', 'vendor/.*'
'tasks/.*'
], ],
mainFile: 'index.php', // Main project file. mainFile: 'index.php', // Main project file.
potFilename: 'mailpoet.pot', // Name of the POT file. potFilename: 'mailpoet.pot', // Name of the POT file.

View File

@ -270,11 +270,12 @@ class StringExtractor {
$line_number = strlen($before) - strlen(str_replace("\n", "", $before)) + 1; $line_number = strlen($before) - strlen(str_replace("\n", "", $before)) + 1;
// extract arguments (potentially multiple) // extract arguments (potentially multiple)
$arguments_pattern = "/([^,\\s][^\\,]*)[^,\\s]*/s"; $arguments_pattern = "/(?s)(?<!\\\\)(\"|')(?:[^\\\\]|\\\\.)*?\\1|[^,\\s]+/";
preg_match_all($arguments_pattern, $matches[2][$i][0], $arguments_matches); preg_match_all($arguments_pattern, $matches[2][$i][0], $arguments_matches);
//echo var_dump($arguments_matches[0]);
$arguments = array(); $arguments = array();
foreach($arguments_matches[1] as $arg) { foreach($arguments_matches[0] as $arg) {
$arguments[] = trim($arg, "'\""); $arguments[] = trim($arg, "'\"");
} }

View File

@ -241,4 +241,4 @@
'mailerResumeSendingButton': __('Resume sending'), 'mailerResumeSendingButton': __('Resume sending'),
'mailerSendingResumedNotice': __('Sending has been resumed.') 'mailerSendingResumedNotice': __('Sending has been resumed.')
}) %> }) %>
<% endblock %> <% endblock %>