2
0
forked from Wavyzz/dolibarr

Complete #33605 by adding phpunit tests

This commit is contained in:
ldestailleur
2025-03-27 10:39:08 +01:00
parent 9cbe86f384
commit df9fea28f1
2 changed files with 23 additions and 12 deletions

View File

@@ -11973,23 +11973,34 @@ function dolExplodeKeepIfQuotes($input)
preg_match_all('/"([^"]*)"|\'([^\']*)\'|(\S+)/', $input, $matches);
// Merge result and delete empty values
return array_filter(array_map(
$result = array_map(
/**
* Return first non-empty item, or empty string
*
* @param string $a Possibly empty item - match ""
* @param string $b Possibly empty item - match ''
* @param string $c Non empty string if $a and $b are empty
*
* @param string $a Matched value in double quotes
* @param string $b Matched value in single quotes
* @param string $c Unquoted value
* @return string
*/
static function ($a, $b, $c) {
return $a ?: ($b ?: $c);
if ($a !== '') return $a;
if ($b !== '') return $b;
if ($c !== '') return $c;
return '';
},
$matches[1],
$matches[2],
$matches[3]
));
);
return array_values(array_filter($result,
/**
* Filter out empty strings from the result array.
*
* @param string $val The value to check.
* @return bool True if the value is not an empty string.
*/
static function ($val) {
return $val !== '';
}));
}