ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:90342] [Ruby trunk Bug#15388] CSV parsing behaviour in > 2.5.0
       [not found] <redmine.issue-15388.20181206174709@ruby-lang.org>
@ 2018-12-06 17:47 ` dharshandj
  2018-12-07  0:02 ` [ruby-core:90343] " nobu
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: dharshandj @ 2018-12-06 17:47 UTC (permalink / raw)
  To: ruby-core

Issue #15388 has been reported by dharshandj@gmail.com (Dharshan Bharathuru).

----------------------------------------
Bug #15388: CSV parsing behaviour in > 2.5.0
https://bugs.ruby-lang.org/issues/15388

* Author: dharshandj@gmail.com (Dharshan Bharathuru)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.5.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
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 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>

~~~



 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:90343] [Ruby trunk Bug#15388] CSV parsing behaviour in > 2.5.0
       [not found] <redmine.issue-15388.20181206174709@ruby-lang.org>
  2018-12-06 17:47 ` [ruby-core:90342] [Ruby trunk Bug#15388] CSV parsing behaviour in > 2.5.0 dharshandj
@ 2018-12-07  0:02 ` nobu
  2018-12-07  0:31 ` [ruby-core:90344] " nobu
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: nobu @ 2018-12-07  0:02 UTC (permalink / raw)
  To: ruby-core

Issue #15388 has been updated by nobu (Nobuyoshi Nakada).

Description updated

Why do you want to write headers when parsing?

----------------------------------------
Bug #15388: CSV parsing behaviour in > 2.5.0
https://bugs.ruby-lang.org/issues/15388#change-75454

* Author: dharshandj@gmail.com (Dharshan Bharathuru)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.5.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
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>

~~~

But without `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>

~~~



 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:90344] [Ruby trunk Bug#15388] CSV parsing behaviour in > 2.5.0
       [not found] <redmine.issue-15388.20181206174709@ruby-lang.org>
  2018-12-06 17:47 ` [ruby-core:90342] [Ruby trunk Bug#15388] CSV parsing behaviour in > 2.5.0 dharshandj
  2018-12-07  0:02 ` [ruby-core:90343] " nobu
@ 2018-12-07  0:31 ` nobu
  2018-12-07  0:49 ` [ruby-core:90345] " dharshandj
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: nobu @ 2018-12-07  0:31 UTC (permalink / raw)
  To: ruby-core

Issue #15388 has been updated by nobu (Nobuyoshi Nakada).


Maybe an error is expected?

```diff
diff --git i/lib/csv.rb w/lib/csv.rb
index dca2a45b6a..e4ad55085c 100644
--- i/lib/csv.rb
+++ w/lib/csv.rb
@@ -687,8 +687,9 @@
   # You pass your +str+ to read from, and an optional +options+ containing
   # anything CSV::new() understands.
   #
-  def self.parse(*args, &block)
-    csv = new(*args)
+  def self.parse(data, write_headers: nil, **options, &block)
+    raise ArgumentError.new("Cannot write headers when parsing") if write_headers
+    csv = new(data, **options)
 
     return csv.each(&block) if block_given?
 
@@ -707,7 +708,8 @@
   #
   # The +options+ parameter can be anything CSV::new() understands.
   #
-  def self.parse_line(line, **options)
+  def self.parse_line(line, write_headers: nil, **options)
+    raise ArgumentError.new("Cannot write headers when parsing") if write_headers
     new(line, options).shift
   end
 
diff --git i/test/csv/test_csv_parsing.rb w/test/csv/test_csv_parsing.rb
index e65bbad92e..7e45a429ef 100755
--- i/test/csv/test_csv_parsing.rb
+++ w/test/csv/test_csv_parsing.rb
@@ -239,6 +239,29 @@
                  CSV.parse("a b  d", col_sep: " "))
   end
 
+  def test_parse_write_headers
+    data = "a,b,c"
+    headers = %w[A B C]
+    Tempfile.create(%w[parsing .csv]) do |f|
+      f.puts data
+      f.close
+      File.open(f.path) {|f|
+        assert_raise(ArgumentError) {
+          CSV.parse(f, write_headers: true, headers: headers)
+        }
+        assert_raise(ArgumentError) {
+          CSV.parse_line(f, write_headers: true, headers: headers)
+        }
+      }
+    end
+    assert_raise(ArgumentError) {
+      CSV.parse(data, write_headers: true, headers: headers)
+    }
+    assert_raise(ArgumentError) {
+      CSV.parse_line(data, write_headers: true, headers: headers)
+    }
+  end
+
   private
 
   def assert_parse_errors_out(*args)
```

----------------------------------------
Bug #15388: CSV parsing behaviour in > 2.5.0
https://bugs.ruby-lang.org/issues/15388#change-75455

* Author: dharshandj@gmail.com (Dharshan Bharathuru)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.5.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
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>

~~~

But without `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>

~~~



 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [ruby-core:90345] [Ruby trunk Bug#15388] CSV parsing behaviour in > 2.5.0
       [not found] <redmine.issue-15388.20181206174709@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2018-12-07  0:31 ` [ruby-core:90344] " nobu
@ 2018-12-07  0:49 ` dharshandj
  2018-12-07  1:44 ` [ruby-core:90347] " nobu
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: dharshandj @ 2018-12-07  0:49 UTC (permalink / raw)
  To: ruby-core

Issue #15388 has been updated by dharshandj@gmail.com (Dharshan Bharathuru).


nobu (Nobuyoshi Nakada) wrote:
> Why do you want to write headers when parsing?

I needed a object-key reference in future references instead of index based references.

----------------------------------------
Bug #15388: CSV parsing behaviour in > 2.5.0
https://bugs.ruby-lang.org/issues/15388#change-75456

* Author: dharshandj@gmail.com (Dharshan Bharathuru)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.5.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
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>

~~~

But without `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>

~~~



 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:90347] [Ruby trunk Bug#15388] CSV parsing behaviour in > 2.5.0
       [not found] <redmine.issue-15388.20181206174709@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2018-12-07  0:49 ` [ruby-core:90345] " dharshandj
@ 2018-12-07  1:44 ` nobu
  2018-12-07  1:59 ` [ruby-core:90348] " kou
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: nobu @ 2018-12-07  1:44 UTC (permalink / raw)
  To: ruby-core

Issue #15388 has been updated by nobu (Nobuyoshi Nakada).


dharshandj@gmail.com (Dharshan Bharathuru) wrote:
> I needed a object-key reference in future references instead of index based references.

It doesn't need to write headers.

----------------------------------------
Bug #15388: CSV parsing behaviour in > 2.5.0
https://bugs.ruby-lang.org/issues/15388#change-75458

* Author: dharshandj@gmail.com (Dharshan Bharathuru)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.5.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
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>

~~~

But without `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>

~~~



 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:90348] [Ruby trunk Bug#15388] CSV parsing behaviour in > 2.5.0
       [not found] <redmine.issue-15388.20181206174709@ruby-lang.org>
                   ` (4 preceding siblings ...)
  2018-12-07  1:44 ` [ruby-core:90347] " nobu
@ 2018-12-07  1:59 ` kou
  2018-12-07  2:07 ` [ruby-core:90349] [Ruby trunk Bug#15388][Assigned] " kou
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 9+ messages in thread
From: kou @ 2018-12-07  1:59 UTC (permalink / raw)
  To: ruby-core

Issue #15388 has been updated by kou (Kouhei Sutou).


It seems that this has been fixed in csv master.
I've released csv gem 3.0.1. Can you try it?

----------------------------------------
Bug #15388: CSV parsing behaviour in > 2.5.0
https://bugs.ruby-lang.org/issues/15388#change-75459

* Author: dharshandj@gmail.com (Dharshan Bharathuru)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.5.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
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>

~~~

But without `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>

~~~



 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:90349] [Ruby trunk Bug#15388][Assigned] CSV parsing behaviour in > 2.5.0
       [not found] <redmine.issue-15388.20181206174709@ruby-lang.org>
                   ` (5 preceding siblings ...)
  2018-12-07  1:59 ` [ruby-core:90348] " kou
@ 2018-12-07  2:07 ` kou
  2018-12-07  3:05 ` [ruby-core:90354] [Ruby trunk Bug#15388] " dharshandj
  2018-12-07  3:24 ` [ruby-core:90355] [Ruby trunk Bug#15388][Closed] " kou
  8 siblings, 0 replies; 9+ messages in thread
From: kou @ 2018-12-07  2:07 UTC (permalink / raw)
  To: ruby-core

Issue #15388 has been updated by kou (Kouhei Sutou).

Status changed from Open to Assigned
Assignee set to kou (Kouhei Sutou)

Arguments validation may be better but we need more works for it. For example, we need to add similar logic to `CSV.read` for this case.

Anyone who wants to work on argument validation should send pull requests to https://github.com/ruby/csv .

----------------------------------------
Bug #15388: CSV parsing behaviour in > 2.5.0
https://bugs.ruby-lang.org/issues/15388#change-75460

* Author: dharshandj@gmail.com (Dharshan Bharathuru)
* Status: Assigned
* Priority: Normal
* Assignee: kou (Kouhei Sutou)
* Target version: 
* ruby -v: 2.5.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
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>

~~~

But without `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>

~~~



 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:90354] [Ruby trunk Bug#15388] CSV parsing behaviour in > 2.5.0
       [not found] <redmine.issue-15388.20181206174709@ruby-lang.org>
                   ` (6 preceding siblings ...)
  2018-12-07  2:07 ` [ruby-core:90349] [Ruby trunk Bug#15388][Assigned] " kou
@ 2018-12-07  3:05 ` dharshandj
  2018-12-07  3:24 ` [ruby-core:90355] [Ruby trunk Bug#15388][Closed] " kou
  8 siblings, 0 replies; 9+ messages in thread
From: dharshandj @ 2018-12-07  3:05 UTC (permalink / raw)
  To: ruby-core

Issue #15388 has been updated by dharshandj@gmail.com (Dharshan Bharathuru).


kou (Kouhei Sutou) wrote:
> It seems that this has been fixed in csv master.
> I've released csv gem 3.0.1. Can you try it?

Thanks. Working fine with version 3.0.1.

----------------------------------------
Bug #15388: CSV parsing behaviour in > 2.5.0
https://bugs.ruby-lang.org/issues/15388#change-75465

* Author: dharshandj@gmail.com (Dharshan Bharathuru)
* Status: Assigned
* Priority: Normal
* Assignee: kou (Kouhei Sutou)
* Target version: 
* ruby -v: 2.5.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
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>

~~~

But without `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>

~~~



 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [ruby-core:90355] [Ruby trunk Bug#15388][Closed] CSV parsing behaviour in > 2.5.0
       [not found] <redmine.issue-15388.20181206174709@ruby-lang.org>
                   ` (7 preceding siblings ...)
  2018-12-07  3:05 ` [ruby-core:90354] [Ruby trunk Bug#15388] " dharshandj
@ 2018-12-07  3:24 ` kou
  8 siblings, 0 replies; 9+ messages in thread
From: kou @ 2018-12-07  3:24 UTC (permalink / raw)
  To: ruby-core

Issue #15388 has been updated by kou (Kouhei Sutou).

Status changed from Assigned to Closed

OK. I'll close this.

----------------------------------------
Bug #15388: CSV parsing behaviour in > 2.5.0
https://bugs.ruby-lang.org/issues/15388#change-75466

* Author: dharshandj@gmail.com (Dharshan Bharathuru)
* Status: Closed
* Priority: Normal
* Assignee: kou (Kouhei Sutou)
* Target version: 
* ruby -v: 2.5.1
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
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>

~~~

But without `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>

~~~



 



-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-12-07  3:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15388.20181206174709@ruby-lang.org>
2018-12-06 17:47 ` [ruby-core:90342] [Ruby trunk Bug#15388] CSV parsing behaviour in > 2.5.0 dharshandj
2018-12-07  0:02 ` [ruby-core:90343] " nobu
2018-12-07  0:31 ` [ruby-core:90344] " nobu
2018-12-07  0:49 ` [ruby-core:90345] " dharshandj
2018-12-07  1:44 ` [ruby-core:90347] " nobu
2018-12-07  1:59 ` [ruby-core:90348] " kou
2018-12-07  2:07 ` [ruby-core:90349] [Ruby trunk Bug#15388][Assigned] " kou
2018-12-07  3:05 ` [ruby-core:90354] [Ruby trunk Bug#15388] " dharshandj
2018-12-07  3:24 ` [ruby-core:90355] [Ruby trunk Bug#15388][Closed] " kou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).