Closed (fixed)
Project:
Power Import
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
8 Sep 2010 at 14:05 UTC
Updated:
7 Dec 2010 at 16:14 UTC
Jump to comment: Most recent file
MS Excel for Mac exports the CSV with funny line endings (if you do a less or vim on the file it shows '^M' symbols instead of new lines). I attached the file in question as an example.
Currently PImport doesn't take this case into consideration and thus sees the CSV as being just one line.
The attached patch normalizes the line endings.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | normalize_line_endings_2.patch | 1.34 KB | andreiashu |
| normalize_line_endings_1.patch | 1.32 KB | andreiashu | |
| metadata_20100908_025202.txt | 1.92 KB | andreiashu |
Comments
Comment #1
andreiashu commentedComment #2
pobster commentedGood catch but two things;
function _pimport_normalize_line_endings($s)$s is not a variable name - it's a letter ;o) Use $string, $input, etc - it makes the code easier for other people to read. Meaningful variable names really do help with debugging, module names however - yeah they can be as random as you like ;o)
This doesn't need duplication, we could just as easily use;
$s = str_replace(array("\r\n", "\r"), "\n", $s);It still reads fine.
Thanks,
Pobster
Comment #3
andreiashu commentedCool, thanks for the code review.
The attached patch should address your remarks. ;-)
Let me know if there are any other issues.
Thanks,
Andrei
Comment #4
pobster commentedLooks good to me, will test it tonight and commit it (unless Marcus can test and commit it sooner?)
* Setting to reviewed and tested because I can see that it'll work but I'll still actually physically test it later! ;o)
Thanks,
Pobster
Comment #5
pobster commentedApologies, I completely forgot to commit this, even though I did actually remember to test it!
I see that you've already committed it (and rightly so!) so marking this as fixed.
Thanks,
Pobster
Comment #7
marcus_clements commentedI've just realised that this patch means that blank lines are removed before the file is processed which means the row counting doesn't work properly for reporting. I think it's more important to give accurate row numbers for problems than to save processing on the import.
I've taken out the code that strips the blank lines and comitted.
Comment #8
pobster commentedJust remove this one line;
Pobster
edit: Oh umm... READ Pobster, READ... You said that already ;o)
Comment #9
andreiashu commented@rayvaughn: agreed.
Initially I thought that removing that line of code you'll still have the same problem (wrong row counting) for files that have funny line endings. But it should actually work ok. I would suggest testing it with the file at the beginning of this issue just to make sure.
Comment #10
marcus_clements commented