infused/dbf — Issue #37: Columns with spaces cause syntax error
Author: ryanwilliams
Created: 2012-02-02 04:57:39+00:00
State: open

I have encountered .dbf files that have columns with spaces in their names. This causes the eval in 'define_accessors' to generate a syntax error due to it including the space in the method name and in the ivar.

Problem is here:

https://github.com/infused/dbf/blob/master/lib/dbf/record.rb#L51

I'm not sure the best way to fix it, replacing space with underscore is quick and easy but what if another column exists that is the same name but with an underscore instead of a space?

Here's a very small example .dbf with this issue:

http://dl.dropbox.com/u/8491051/bad.dbf

Which results in:

SyntaxError: (eval):2: syntax error, unexpected tIDENTIFIER, expecting keyword_end
@fiber b_id ||= attributes['fiber b_id']
^
from /Users/Ryan/.rvm/gems/ruby-1.9.3-p0/gems/dbf-1.7.2/lib/dbf/record.rb:53:in `class_eval'
from /Users/Ryan/.rvm/gems/ruby-1.9.3-p0/gems/dbf-1.7.2/lib/dbf/record.rb:53:in `block in define_accessors'
from /Users/Ryan/.rvm/gems/ruby-1.9.3-p0/gems/dbf-1.7.2/lib/dbf/record.rb:51:in `each'