diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 358fe41e38e..07b70220575 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -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 !== ''; + })); } diff --git a/test/phpunit/FunctionsLibTest.php b/test/phpunit/FunctionsLibTest.php index 632f2a1e223..6b5d460cb7c 100644 --- a/test/phpunit/FunctionsLibTest.php +++ b/test/phpunit/FunctionsLibTest.php @@ -1993,8 +1993,8 @@ class FunctionsLibTest extends CommonClassTest $this->assertEquals("a", $result[0]); $this->assertEquals("b c", $result[1]); - //$result = dolExplodeKeepIfQuotes("1 0"); - //$this->assertEquals("1", $result[0]); - //$this->assertEquals("0", $result[1]); + $result = dolExplodeKeepIfQuotes("1 0"); + $this->assertEquals("1", $result[0]); + $this->assertEquals("0", $result[1]); } }