Project

General

Profile

Bug #15388

Updated by nobu (Nobuyoshi Nakada) over 5 years ago

Hi, 

 It seems like CSV library in 2.5.0 is not behaving as intended while parsing. 

 ~~~ ruby 
 header = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q"] 

 csv_str = "10.4710|859.5170|9000.0000|Y||0.0000||NRM|0||||N|Y|P|NRM|\r\n11.4710|869.5170|9000.0000|Y||0.0000||NRM|0||||N|Y|P|NRM|\r\n" 

 CSV.parse(csv_str, col_sep: '|', write_headers: true, headers: header)[0] 
 # produces junk 
 # #<CSV::Row "A":"0" "B":nil "C":"NRM" "D":"0" "E":nil "F":nil "G":nil "H":"N" "I":"Y" "J":"P" "K":"NRM" "L":nil "M":nil "N":nil "O":nil "P":nil "Q":nil> 

 ~~~ 

 ~~~ ruby 
 But without `write_headers` write_headers option it produces correct parsing. 
 ~~~ 

 ~~~ ruby 
 CSV.parse(csv_str, col_sep: '|', headers: header)[0] 

 # #<CSV::Row "A":"10.4710" "B":"859.5170" "C":"9000.0000" "D":"Y" "E":nil "F":"0.0000" "G":nil "H":"NRM" "I":"0" "J":nil "K":nil "L":nil "M":"N" "N":"Y" "O":"P" "P":"NRM" "Q":nil> 

 ~~~ 



 

Back