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

Bug #16972 symmetrize() does not compute the $max_length correctly and thus breaks.
Submitted: 2010-01-06 14:08 UTC
From: krozinov Assigned: ktlacaelel
Status: Closed Package: File_CSV_DataSource (version 1.0.0)
PHP Version: Irrelevant OS: Ubuntu
Roadmaps: 1.0.1    
Subscription  


Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem : 43 - 36 = ?

 
 [2010-01-06 14:08 UTC] krozinov (Konstantin Rozinov)
Description: ------------ The symmetrize() function does not compute the $max_length correctly. Right now, it goes through each of the rows and finds the longest row and sets $max_length to it. But in the next section of code it only checks if ($max_length == 0). It should also check if $max_length is less than $header_length in cases where the $header_length is longer than any of the $row_length. I've pasted the patch code in the "Test Script" section. Additionally, the documentation says the symmetrize() should return an array, but currently it doesn't. Either the documentation should be updated or the function should return an array. Thanks, Konstantin Test script: --------------- Replace lines 447-449 in v1.0.0 with the following to get the correct behavior: $header_length = count($this->headers); if (($max_length == 0) || ($header_length > $max_length)) { $max_length = $header_length; }

Comments

 [2010-01-07 03:27 UTC] doconnor (Daniel O'Connor)
Can we have an actual executable test script to demonstrate the problem?
 [2010-01-07 03:50 UTC] krozinov (Konstantin Rozinov)
Here is the code to show the problem: require('File/CSV/DataSource.php'); $csv = new File_CSV_DataSource; /* Load and parse the CSV file. */ if ($csv->load($_FILES['import_contacts']['tmp_name']) === true) { /* Outlook CSV is notoriously *not* symmetric. */ if ($csv->isSymmetric() === false) { /* Make the length of all rows and headers the same. */ $csv->symmetrize(); } $data = $csv->connect(); } The symmetrize() function will not properly "symmetrize" the data if the header is longer than any of the rows (as is the case in Outlook CSV files, which I have attached in the next comment so you can test it yourself) Thanks, Konstantin
 [2010-01-07 03:52 UTC] krozinov (Konstantin Rozinov)
 [2010-01-20 11:15 UTC] ktlacaelel (Kazuyoshi Tlacaelel)
Whoops, didn't notice this bug until now. I would give it a quick check but please provide the current php version that you are running!
 [2010-01-21 03:37 UTC] krozinov (Konstantin Rozinov)
I am running PHP 5.3.1.
 [2010-01-21 15:59 UTC] ktlacaelel (Kazuyoshi Tlacaelel)
Thanks for the version, yeah perhaps your right! I will have this fixed sometime this week. Just one observation: *The patch* which is a csv file. is not quoted correctly! some lines start with only one quote and some end with an unclosed one. Example: header_1, header_2 field_1, field_2 field_1, " ", field_2 you might wanna watch out for those as well!
 [2010-02-12 13:53 UTC] ktlacaelel (Kazuyoshi Tlacaelel)
-Status: Open +Status: Closed -Assigned To: +Assigned To: ktlacaelel