Skip to content

Commit

Permalink
Fix: [ bug Dolibarr#253 ] Non UTF-8 characters in CSV exports
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Dec 21, 2011
1 parent b75688f commit 721c9a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions htdocs/core/lib/functions.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3524,12 +3524,13 @@ function picto_required()
*
* @param StringHtml String to clean
* @param removelinefeed Replace also all lines feeds by a space
* @param pagecodeto Encoding of input string
* @return string String cleaned
*/
function dol_string_nohtmltag($StringHtml,$removelinefeed=1)
function dol_string_nohtmltag($StringHtml,$removelinefeed=1,$pagecodeto='UTF-8')
{
$pattern = "/<[^>]+>/";
$temp = dol_entity_decode($StringHtml);
$temp = dol_entity_decode($StringHtml,$pagecodeto);
$temp = preg_replace($pattern,"",$temp);

// Supprime aussi les retours
Expand Down
10 changes: 5 additions & 5 deletions htdocs/core/modules/export/export_csv.modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function write_title($array_export_fields_label,$array_selected_sorted,$outputla
foreach($array_selected_sorted as $code => $value)
{
$newvalue=$outputlangs->transnoentities($array_export_fields_label[$code]);
$newvalue=$this->csv_clean($newvalue);
$newvalue=$this->csv_clean($newvalue,$outputlangs->charset_output);

fwrite($this->handle,$newvalue.$this->separator);
}
Expand Down Expand Up @@ -206,7 +206,6 @@ function write_record($array_selected_sorted,$objp,$outputlangs)
{
$alias=str_replace(array('.','-'),'_',$code);
if (empty($alias)) dol_print_error('','Bad value for field with key='.$code.'. Try to redefine export.');

$newvalue=$outputlangs->convToOutputCharset($objp->$alias);

// Translation newvalue
Expand All @@ -215,7 +214,7 @@ function write_record($array_selected_sorted,$objp,$outputlangs)
$newvalue=$outputlangs->transnoentities($reg[1]);
}

$newvalue=$this->csv_clean($newvalue);
$newvalue=$this->csv_clean($newvalue,$outputlangs->charset_output);

fwrite($this->handle,$newvalue.$this->separator);
$this->col++;
Expand Down Expand Up @@ -251,14 +250,15 @@ function close_file()
* Clean a cell to respect rules of CSV file cells
*
* @param string $newvalue String to clean
* @param string $charset Output character set
* @return string Value cleaned
*/
function csv_clean($newvalue)
function csv_clean($newvalue, $charset)
{
$addquote=0;

// Rule Dolibarr: No HTML
$newvalue=dol_string_nohtmltag($newvalue);
$newvalue=dol_string_nohtmltag($newvalue,1,$charset);

// Rule 1 CSV: No CR, LF in cells
$newvalue=str_replace("\r",'',$newvalue);
Expand Down

0 comments on commit 721c9a6

Please sign in to comment.