Tk Library Source Code

Artifact [b97d92d211]
Login

Artifact b97d92d2116ade207809476bb40a32a8b5499129:

Attachment "565051.diff" to ticket [565051ffff] added by andreas_kupries 2002-06-25 06:16:20.
? modules/fileinput
? modules/csv/csv-new.tcl
? modules/ftp/example
? modules/ftpd/examples
Index: ChangeLog
===================================================================
RCS file: /cvsroot/tcllib/tcllib/ChangeLog,v
retrieving revision 1.157
diff -u -r1.157 ChangeLog
--- ChangeLog	24 Jun 2002 21:39:45 -0000	1.157
+++ ChangeLog	24 Jun 2002 23:14:50 -0000
@@ -1,5 +1,7 @@
 2002-06-24  Andreas Kupries  <[email protected]>
 
+	* csv: Fixed bug #565051.
+
 	* mime: Fixed SF bug #548832.
 
 2002-06-17  Andreas Kupries  <[email protected]>
Index: modules/csv/ChangeLog
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/csv/ChangeLog,v
retrieving revision 1.12
diff -u -r1.12 ChangeLog
--- modules/csv/ChangeLog	26 Mar 2002 07:40:36 -0000	1.12
+++ modules/csv/ChangeLog	24 Jun 2002 23:14:50 -0000
@@ -1,3 +1,17 @@
+2002-06-24  Andreas Kupries  <[email protected]>
+
+	* csv.tcl (csv::split): Fixed bug #565051, found by Tod A. olson
+	  <[email protected]>. The described bug is actually
+	  none, given the definition of the CSV format, but the examples
+	  do contain a related bug. Just swap what is seen as ok and
+	  bug. Because of this the provided patched code was rejected, and
+	  a new patch created. The patched code passes the extended
+	  testsuite (see below).
+
+	* csv.test: Extended testsuite regarding the handling of empty
+	  fields and quote characters. Part of the investigation into bug
+	  #565051.
+
 2002-03-25  Andreas Kupries  <[email protected]>
 
 	* csv.man: Fixed formatting errors in the doctools manpage.
Index: modules/csv/csv.tcl
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/csv/csv.tcl,v
retrieving revision 1.9
diff -u -r1.9 csv.tcl
--- modules/csv/csv.tcl	1 Feb 2002 22:59:08 -0000	1.9
+++ modules/csv/csv.tcl	24 Jun 2002 23:14:50 -0000
@@ -170,6 +170,8 @@
 #	A list of the values in 'line'.
 
 proc ::csv::split {line {sepChar ,}} {
+    regsub -- "$sepChar\"\"$" $line $sepChar\0\"\"\0 line
+    regsub -- "^\"\"$sepChar" $line \0\"\"\0$sepChar line
     regsub -all -- {(^\"|\"$)} $line \0 line
     set line [string map [list \
 	    $sepChar\"\"\" $sepChar\0\" \
Index: modules/csv/csv.test
===================================================================
RCS file: /cvsroot/tcllib/tcllib/modules/csv/csv.test,v
retrieving revision 1.5
diff -u -r1.5 csv.test
--- modules/csv/csv.test	1 Feb 2002 22:59:08 -0000	1.5
+++ modules/csv/csv.test	24 Jun 2002 23:14:50 -0000
@@ -63,6 +63,138 @@
     ::csv::split [::csv::join $x]
 } [list "\"hello, you\"" a b c]
 
+test csv-1.8-1 {split empty fields} {
+    csv::split {1 2 "" ""} { }
+} {1 2 {"} {"}}
+
+test csv-1.9-1 {split empty fields} {
+    csv::split {1 2 3 ""} { }
+} {1 2 3 {"}}
+
+test csv-1.10-1 {split empty fields} {
+    csv::split {"" "" 1 2} { }
+} {{"} {"} 1 2}
+
+test csv-1.11-1 {split empty fields} {
+    csv::split {"" 0 1 2} { }
+} {{"} 0 1 2}
+
+test csv-1.12-1 {split empty fields} {
+    csv::split {"" ""} { }
+} {{"} {"}}
+
+test csv-1.13-1 {split empty fields} {
+    csv::split {"" "" ""} { }
+} {{"} {"} {"}}
+
+test csv-1.14-1 {split empty fields} {
+    csv::split {"" 0 "" 2} { }
+} {{"} 0 {"} 2}
+
+test csv-1.15-1 {split empty fields} {
+    csv::split {1 "" 3 ""} { }
+} {1 {"} 3 {"}}
+
+test csv-1.8-2 {split empty fields} {
+    csv::split "1,2,,"
+} {1 2 {} {}}
+
+test csv-1.9-2 {split empty fields} {
+    csv::split "1,2,3,"
+} {1 2 3 {}}
+
+test csv-1.10-2 {split empty fields} {
+    csv::split ",,1,2"
+} {{} {} 1 2}
+
+test csv-1.11-2 {split empty fields} {
+    csv::split ",0,1,2"
+} {{} 0 1 2}
+
+test csv-1.12-2 {split empty fields} {
+    csv::split ","
+} {{} {}}
+
+test csv-1.13-2 {split empty fields} {
+    csv::split ",,"
+} {{} {} {}}
+
+test csv-1.14-2 {split empty fields} {
+    csv::split ",0,,2"
+} {{} 0 {} 2}
+
+test csv-1.15-2 {split empty fields} {
+    csv::split "1,,3,"
+} {1 {} 3 {}}
+
+test csv-1.8-3 {split empty fields} {
+    csv::split {1 2  } { }
+} {1 2 {} {}}
+
+test csv-1.9-3 {split empty fields} {
+    csv::split {1 2 3 } { }
+} {1 2 3 {}}
+
+test csv-1.10-3 {split empty fields} {
+    csv::split {  1 2} { }
+} {{} {} 1 2}
+
+test csv-1.11-3 {split empty fields} {
+    csv::split { 0 1 2} { }
+} {{} 0 1 2}
+
+test csv-1.12-3 {split empty fields} {
+    csv::split { } { }
+} {{} {}}
+
+test csv-1.13-3 {split empty fields} {
+    csv::split {  } { }
+} {{} {} {}}
+
+test csv-1.14-3 {split empty fields} {
+    csv::split { 0  2} { }
+} {{} 0 {} 2}
+
+test csv-1.15-3 {split empty fields} {
+    csv::split {1  3 } { }
+} {1 {} 3 {}}
+
+
+test csv-1.8-4 {split empty fields} {
+    csv::split {1,2,"",""}
+} {1 2 {"} {"}}
+
+test csv-1.9-4 {split empty fields} {
+    csv::split {1,2,3,""}
+} {1 2 3 {"}}
+
+test csv-1.10-4 {split empty fields} {
+    csv::split {"","",1,2}
+} {{"} {"} 1 2}
+
+test csv-1.11-4 {split empty fields} {
+    csv::split {"",0,1,2}
+} {{"} 0 1 2}
+
+test csv-1.12-4 {split empty fields} {
+    csv::split {"",""}
+} {{"} {"}}
+
+test csv-1.13-4 {split empty fields} {
+    csv::split {"","",""}
+} {{"} {"} {"}}
+
+test csv-1.14-4 {split empty fields} {
+    csv::split {"",0,"",2}
+} {{"} 0 {"} 2}
+
+test csv-1.15-4 {split empty fields} {
+    csv::split {1,"",3,""}
+} {1 {"} 3 {"}}
+
+
+
+
 test csv-2.1 {join} {
     csv::join {123 {"a"} {} hello}
 } $str1a