Project

General

Profile

Feature #12839

CSV - Give not nil but empty strings for empty fields

Added by 5.5 (5 5) 12 months ago. Updated 9 months ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:77623]

Description

The CSV parser gives nil for empty fields.

require "csv"

CSV.parse(%|,""|) #=> [[nil, ""]]

The above behavior maybe be suitable for certain programmers, but I hope to get [["", ""]].

So I had used to write the following code reluctantly till Ruby 2.1:

require "csv"

CSV.parse(%|,""|, converters: lambda{|v| v || ""})
#=> [["", ""]]

It is wasteful, but certainly works for my purpose.

However, because of #11126, the above code does not work from Ruby 2.2.
(Converters are not called for nil)

I merely want an option, which makes the CSV parser give empty strings for empty fields.

Namely,

require "csv"

CSV.parse(%|,""|, string: true) #=> [["", ""]]

Related issues

Related to Ruby trunk - Bug #11126: CSV field converters doesn't attempt to convert nil value.Closed

History

#1 Updated by shyouhei (Shyouhei Urabe) 9 months ago

  • Related to Bug #11126: CSV field converters doesn't attempt to convert nil value. added

#2 [ruby-core:78781] Updated by shyouhei (Shyouhei Urabe) 9 months ago

  • Assignee set to JEG2 (James Gray)

Currently no active developers are there for CSV.

I heard the distinguish between silent and sound empty cells are intentional. However I have no idea if converter issue is a bug or design.

Also available in: Atom PDF