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() {
return $this->_exec('./node_modules/.bin/grunt makepot'.
' --gruntfile '.__DIR__.'/tasks/makepot/makepot.js'.
' --base_path '.__DIR__
);
}
function pushpot() {
return $this->_exec('./node_modules/.bin/grunt pushpot'.
' --gruntfile '.__DIR__.'/tasks/makepot/makepot.js'.
' --base_path '.__DIR__
' --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
domainPath: 'lang', // where to save the .pot
exclude: [
'build/.*',
'assets/.*',
'lang/.*',
'node_modules/.*',
'plugin_repository/.*',
'tasks/.*',
'tests/.*',
'vendor/.*',
'tasks/.*'
'vendor/.*'
],
mainFile: 'index.php', // Main project 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;
// 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);
//echo var_dump($arguments_matches[0]);
$arguments = array();
foreach($arguments_matches[1] as $arg) {
foreach($arguments_matches[0] as $arg) {
$arguments[] = trim($arg, "'\"");
}