Hello,

There is an issue with csv parser, where if a quoted field is followed 
immediately by newline, the newline is ignored.

The following test demonstrates the problem; and a fix.

Cheers,
Philip

diff --git a/extra/csv/csv-tests.factor b/extra/csv/csv-tests.factor
index 6ab26c7..858736a 100644
--- a/extra/csv/csv-tests.factor
+++ b/extra/csv/csv-tests.factor
@@ -46,9 +46,11 @@ IN: csv.tests
 [ "Year,Make,Model\n1997,Ford,E350\n2000,Mercury,Cougar" 
    <string-reader> csv ] named-unit-test
 
-   
+"Quoted field followed immediately by newline"
+[ { { "foo" "bar" }
+    { "1"   "2" } } ]
+[ "foo,\"bar\"\n1,2" <string-reader> csv ] named-unit-test
 
-   
 ! !!!!!!!!  other tests
    
 [ { { "Phil Dawes" } } ] 
diff --git a/extra/csv/csv.factor b/extra/csv/csv.factor
index 3953ce0..b1953f5 100644
--- a/extra/csv/csv.factor
+++ b/extra/csv/csv.factor
@@ -31,6 +31,7 @@ VAR: delimiter
   read1 dup 
   { { CHAR: "    [ , quoted-field ] }  ! " is an escaped quote
     { delimiter> [ ] }                 ! end of quoted field 
+    { CHAR: \n   [ ] }
     [ 2drop skip-to-field-end ]       ! end of quoted field + padding
   } case ;


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to