From:             pahan at hubbitus dot spb dot su
Operating system: Linux
PHP version:      5.3.1
PHP Bug Type:     Filesystem function related
Bug description:  fgetcsv is not binary-safe in different locales

Description:
------------
If in unicode locale we construct CSV-file by fputcsv some values, such as
single words does not enclosed (even if enclosing character was directly
provided). Because that, in different locale file can't be parsed properly.
Be aware, I seen note in documentation, but I speak about binary-safe
parsing, do not interpret any symbols.

In followed example we get result csv-string:
Test;ÂÕáâ;"´ÒÐ áÛÞÒÐ"
Single wod is not enclosed. And I do not seen parameter to force enclosing
it. But, it can completely solve problem! So, csv-string:
"Test";"ÂÕáâ";"´ÒÐ áÛÞÒÐ"
correctly parsed in any locale (I repeat, I do not speak about further
symbol interpretation)!

So, as easy fix, which also should not produce any backward capability
problem my suggestion is add parameter to fputcsv to force enclosing
fields, even if it consist from 1 word. Or, may be even do this as default
behavior.

Reproduce code:
---------------
<?
$fp = fopen('php://temp', 'w');
fputcsv($fp, array('Test', 'ÂÕáâ', '´ÒÐ áÛÞÒÐ'), ';', '"');
rewind($fp);
echo(stream_get_contents($fp));
rewind($fp);
var_dump(fgetcsv($fp, 0, ';', '"'));
setlocale(LC_ALL, 'C');
rewind($fp);
var_dump(fgetcsv($fp, 0, ';', '"'));
?>

Expected result:
----------------
Test;ÂÕáâ;"´ÒÐ áÛÞÒÐ"
array(3) {
  [0]=>
  string(4) "Test"
  [1]=>
  string(8) "ÂÕáâ"
  [2]=>
  string(17) "´ÒÐ áÛÞÒÐ"
}
array(3) {
  [0]=>
  string(4) "Test"
  [1]=>
  string(0) "ÂÕáâ"
  [2]=>
  string(17) "´ÒÐ áÛÞÒÐ"
}


Actual result:
--------------
Test;ÂÕáâ;"´ÒÐ áÛÞÒÐ"
array(3) {
  [0]=>
  string(4) "Test"
  [1]=>
  string(8) "ÂÕáâ"
  [2]=>
  string(17) "´ÒÐ áÛÞÒÐ"
}
array(3) {
  [0]=>
  string(4) "Test"
  [1]=>
  string(0) ""
  [2]=>
  string(17) "´ÒÐ áÛÞÒÐ"
}


-- 
Edit bug report at http://bugs.php.net/?id=50456&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=50456&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=50456&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=50456&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=50456&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=50456&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=50456&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=50456&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=50456&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=50456&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=50456&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=50456&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=50456&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=50456&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=50456&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=50456&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=50456&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=50456&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=50456&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=50456&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=50456&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=50456&r=mysqlcfg

Reply via email to