Fix #huntrf0ffd01e-8054-4e43-96f7-a0d2e652ac7e

This commit is contained in:
Laurent Destailleur 2023-02-17 17:55:46 +01:00
parent bda4def933
commit d976372d87

View File

@ -334,7 +334,7 @@ function barcode_encode_upc($upc, $encoding = "UPC")
*/ */
function barcode_encode_genbarcode($code, $encoding) function barcode_encode_genbarcode($code, $encoding)
{ {
global $genbarcode_loc; global $conf, $db, $genbarcode_loc;
// Clean parameters // Clean parameters
if (preg_match("/^ean$/i", $encoding) && strlen($code) == 13) { if (preg_match("/^ean$/i", $encoding) && strlen($code) == 13) {
@ -343,27 +343,34 @@ function barcode_encode_genbarcode($code, $encoding)
if (!$encoding) { if (!$encoding) {
$encoding = "ANY"; $encoding = "ANY";
} }
$encoding = preg_replace("/[\\\|]/", "_", $encoding); $encoding = dol_string_nospecial($encoding, '_');
$code = preg_replace("/[\\\|]/", "_", $code); $code = dol_string_nospecial($code, "_");
$command = escapeshellarg($genbarcode_loc); $command = escapeshellarg($genbarcode_loc);
//$paramclear=" \"".str_replace("\"", "\\\"",$code)."\" \"".str_replace("\"", "\\\"",strtoupper($encoding))."\"";
$paramclear = " ".escapeshellarg($code)." ".escapeshellarg(strtoupper($encoding)); $paramclear = " ".escapeshellarg($code)." ".escapeshellarg(strtoupper($encoding));
$fullcommandclear = $command." ".$paramclear." 2>&1"; $fullcommandclear = $command." ".$paramclear." 2>&1";
//print $fullcommandclear."<br>\n";exit; //print $fullcommandclear."<br>\n";exit;
dol_syslog("Run command ".$fullcommandclear); dol_syslog("Run command ".$fullcommandclear);
$fp = popen($fullcommandclear, "r");
if ($fp) { $outputfile = $conf->user->dir_temp.'/genbarcode.tmp'; // File used with popen method
$bars = fgets($fp, 1024);
$text = fgets($fp, 1024); // Execute a CLI
$encoding = fgets($fp, 1024); include_once DOL_DOCUMENT_ROOT.'/core/class/utils.class.php';
pclose($fp); $utils = new Utils($db);
$result = $utils->executeCLI($fullcommandclear, $outputfile);
if (!empty($result['output'])) {
$tmparr = explode("\n", $result['output']);
$bars = $tmparr[0];
$text = $tmparr[1];
$encoding = $tmparr[2];
} else { } else {
dol_syslog("barcode.lib.php::barcode_encode_genbarcode failed to run popen ".$fullcommandclear, LOG_ERR); dol_syslog("barcode.lib.php::barcode_encode_genbarcode failed to run ".$fullcommandclear, LOG_ERR);
return false; return false;
} }
//var_dump($bars); //var_dump($bars);
$ret = array( $ret = array(
"bars" => trim($bars), "bars" => trim($bars),