mabart / parsecsv-for-php

Automatically exported from code.google.com/p/parsecsv-for-php
MIT License
0 stars 0 forks source link

Incorrect delimiter evalution using auto() on single-column csv files #8

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
>>What steps will reproduce the problem?
1. Obtain the basic.php file from the download and the attached _books.csv.
2. The attached _books.csv file has a single column, and has some 0's
peppered in the text of some of the rows.
3. Run basic.php.

>>What is the expected output? What do you see instead?
The file should parse as an array with a single member in each row, instead
the auto() function is evaluating the 0's as delimeters. Since there are no
delimeters used in the file, the $this->delimiter variable in
parsecsv.lib.php is empty. The subsequent evaluation on line 379 in
parsecsv.lib.php, since it only uses ==, is evaluating the 0's in the file
as equal to the blank delimeter.

>>What version of the product are you using? On what operating system?
Tested in 0.3.1 and 0.3.2 on RedHat

>>Please provide any additional information below.
The solution would seem to be to change the line below (line 379) to use
=== instead of == for string comparisons:

} elseif ( ($ch == $this->delimiter || ($ch == "\n" && $pch != "\r") || $ch
== "\r") && !$enclosed ) {

                         Becomes

} elseif ( ($ch === $this->delimiter || ($ch === "\n" && $pch !== "\r") ||
$ch === "\r") && !$enclosed ) {

Original issue reported on code.google.com by jpp...@gmail.com on 10 Jul 2008 at 6:33

Attachments:

GoogleCodeExporter commented 8 years ago
Single-column CSV files is something I recently noticed has some issues, I'll 
be providing a fix and official 
update as soon as I can :)

Original comment by zynode on 10 Jul 2008 at 6:38

GoogleCodeExporter commented 8 years ago
Hi guys,

I suppose the proposed fix doesn't solve the issue completely, when the final 2 
chars of a single column CSV line are "\r\n". 

This combination is not caught as a line-end, which causes the "\n" to be seen 
as a "normal" character, which causes the "\n" to be added to the 
delimiter-character possibilities array (the final "else").

I've added another possibility in the second "if" like follows:

elseif ( ($ch === $this->delimiter || ( $ch === "\n" && $pch !== "\r" ) || $ch 
=== "\r" || $ch === "\n" )  && !$enclosed ) {

Original comment by kim.ken...@gmail.com on 4 Apr 2012 at 1:08