Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.0.0

Bug #5257 File_CSV: delimiter problem if first field is empty
Submitted: 2005-08-31 15:02 UTC
From: ionut at browse dot ro Assigned: dufuz
Status: Closed Package: File_CSV
PHP Version: 5.0.3 OS: linux
Roadmaps: (Not assigned)    
Subscription  


 [2005-08-31 15:02 UTC] ionut at browse dot ro
Description: ------------ If the CSV file contains a row with the first field empty then the whole row is shifted with 1 column and the first comma appears in the second field. Test script: --------------- At line 240 the test logic needed change. Was: if (!$in_quote && ($c == $conf['sep'] || $c == "\n" || $c == "\r") && $prev != '') { Changed to: if (!$in_quote && ((($c == "\n" || $c == "\r") && $prev != '') || ($c == $conf['sep']) ) ) { After the modification the

Comments

 [2005-10-09 01:56 UTC] dufuz
I'm wondering, to you specify the field count your self or do you use the discoverFormat() method ?
 [2005-10-09 02:29 UTC] dufuz
Btw I constructed this easy little example: require_once 'File/CSV.php'; $file = 'test.csv'; $conf = File_CSV::discoverFormat($file); print "Format:\n"; print_r(File_CSV::read('test.csv', $conf)); print "\n"; print_r(File_CSV::read('test.csv', $conf)); print "\n"; print_r(File_CSV::read('test.csv', $conf)); print "\n"; print_r(File_CSV::read('test.csv', $conf)); print "\n"; test.csv contains: "","foo" "foo","" ,foo foo, the output is: Array ( [0] => [1] => foo ) Array ( [0] => foo [1] => ) Array ( [0] => [1] => foo ) Array ( [0] => foo [1] => ) which leads me to think there is no bug, but if you have a test case that can trigger this error then let me know.
 [2007-03-22 21:59 UTC] dufuz (Helgi Þormar)
We are unable to reproduce the bug as reported. Please provide a simple script (10 lines or less) or a link to an external script that can be used to reproduce the bug. If you can provide the script, feel free to add it to this bug and change the status back to "Open". Thank you for your interest in PEAR. Hello any more info on this ?
 [2007-06-09 22:10 UTC] dufuz (Helgi Þormar)
No feedback was provided. The bug is being suspended because we assume that you are no longer experiencing the problem. If this is not the case and you are able to provide the information that was requested earlier, please do so and change the status of the bug back to "Open". Thank you.
 [2008-01-25 02:27 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!
 [2008-01-25 02:36 UTC] ddis11 (Stephen Compall)
I have encountered this issue and put modified versions of pear/File/tests/CSV/bug5257.{phpt,csv} at http://desktopdoctors.info/wsimpl/bug5257-reopen.tar.gz . tentative-fix-1.patch, which works for me and passes all tests that pass in CVS HEAD on my machine, removes the $prev != '' case instead of adding a test as in the reporter's fix.
 [2008-02-27 14:49 UTC] sunejensen (Sune Jensen)
Here is a test example.csv: Field 0, Field 1, Field 2, Field 3, Field 4 ,Field 1,,Field 3, bugTest.php: class bugTest extends PHPUnit_Framework_TestCase { function testParseFileStartingWithADelimiter() { require_once 'File/CSV.php'; $config = File_CSV::discoverFormat('example.csv'); while ($res = File_CSV::readQuoted('example.csv', $config)) $result[] = $res; $expected = array(0 => array(0 => 'Field 0', 1 => 'Field 1', 2 => 'Field 2', 3 => 'Field 3', 4 => 'Field 4'), 1 => array(0 => '',1 => 'Field 1',2 => '',3 => 'Field 3',4 => '')); $this->assertEquals($expected, $result); } }
 [2008-07-06 23:47 UTC] dufuz (Helgi Þormar Þorbjörnsson)
Stephan, your fix does not make your test case pass but also no other test cases started failing. Are you sure it passed for you with this fix ?
 [2008-07-07 02:53 UTC] dufuz (Helgi Þormar Þorbjörnsson)
Actually I have to take that partially back, Stephans test case still fails, Susans passes now if there is a new line after all the CSV data, not if there is no new line, weird huh - But I'm keeping the change in anyway, thanks! Still have the same question for you Stephan, you sure that was the only change you did to get it to pass
 [2008-09-21 23:58 UTC] dufuz (Helgi Þormar Þorbjörnsson)
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.