Project

General

Profile

Actions

Bug #15388

closed

CSV parsing behaviour in > 2.5.0

Added by dharshandj@gmail.com (Dharshan Bharathuru) over 5 years ago. Updated over 5 years ago.

Status:
Closed
Target version:
-
ruby -v:
2.5.1
[ruby-core:90342]

Description

Hi,

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

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>

But without write_headers option it produces correct parsing.

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>

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0