[#9722] Kernel#system broken inside Dir.chdir(&block) if system command doesn't have shell characters — <noreply@...>

Bugs item #7278, was opened at 2006-12-14 13:59

8 messages 2006/12/14

[#9749] System V IPC in standard library? — Steven Jenkins <steven.jenkins@...>

Back in August, I needed a semaphore to serialize access to an external

14 messages 2006/12/19

[#9753] CVS freeze — SASADA Koichi <ko1@...>

Hi,

20 messages 2006/12/20
[#9755] Re: [ruby-dev:30039] CVS freeze — SASADA Koichi <ko1@...> 2006/12/20

Hi,

[#9757] Re: [ruby-dev:30040] Re: CVS freeze — SASADA Koichi <ko1@...> 2006/12/20

Hi,

CSV Issue

From: James Edward Gray II <james@...>
Date: 2006-12-05 16:14:03 UTC
List: ruby-core #9670
Greg Brown located an issue with the CSV library last night.  I won't  
call it "a bug," because everything pretty much works as advertised  
(excepting possibly an == call).  Still, it's surprising behavior  
that can come back to haunt you pretty far down the line:

#!/usr/bin/env ruby -w

require "csv"

require "rubygems"
require "faster_csv"

require "yaml"

data = <<END_DATA
foo,bar,baz
END_DATA

fcsv = FCSV.parse(data).flatten  # => ["foo", "bar", "baz"]
csv  = CSV.parse(data).flatten   # => ["foo", "bar", "baz"]

# a lie
fcsv == csv  # => true

# the truth
fcsv.map { |field| field.class }  # => [String, String, String]
csv.map { |field| field.class }   # => [CSV::Cell, CSV::Cell, CSV::Cell]

# an issue (how the above hurts you)
fcsv_name, csv_name = "fcsv_dump.yaml", "csv_dump.yaml"
File.open(fcsv_name, "w") { |file| YAML.dump(fcsv, file) }
File.open(csv_name, "w") { |file| YAML.dump(csv, file) }
# if you later load without the libraries...
[CSV, FCSV].each { |c| Object.send(:remove_const, c.to_s) }
File.open(fcsv_name) { |file| YAML.load(file) }  # => ["foo", "bar",  
"baz"]
File.open(csv_name) { |file| YAML.load(file) }   # =>
# ~> /usr/local/lib/ruby/1.8/yaml/rubytypes.rb:152:in `yaml_new':  
undefined method `allocate' for "CSV::Cell":String (NoMethodError)
# ~>  from /usr/local/lib/ruby/1.8/yaml.rb:133:in `load'
# ~>  from -:31
# ~>  from -:31

__END__

Just in case people think this is a pretty contrived example, Greg  
actually located the issue while working with the Basecamp API.   
basecamp.rb serializes the data and then sends it up to a server that  
won't have CSV loaded.  This caused Basecamp to toss page redirects  
and made for a very hard to find bug (just because the data was  
originally loaded from CSV).  Together, Greg and I both put in hours  
to track it down.

I think the really issue here is that a CSV::Cell looks like a  
String, but it's not really.  It adds no significant functionality  
either:

   # deprecated
   class Cell < String
     def initialize(data = "", is_null = false)
       super(is_null ? "" : data)
     end

     def data
       to_s
     end
   end

I really think the library should be changed to use regular String  
objects or at least convert fields as they are returned to calling  
code.  I'm hoping the "deprecated" comment indicates that this is  
planned.

James Edward Gray II


In This Thread

Prev Next