Data-Liberation-Front / csvlint.io

Check that your CSV files are valid
http://csvlint.io
MIT License
73 stars 12 forks source link

Revalidate uploaded CSV terminates on successive 'revalidate' dialect requests #195

Open quadrophobiac opened 9 years ago

quadrophobiac commented 9 years ago

Upon uploading CSV for validation (e.g. fixtures/revalidate.csv)

Stack trace reveals that on the three steps pass a different argument to the CSVlint Gem on each pass

  1. Csvlint::Validator.parse_extension(source#StringIO) Csvlint::Validator.initialize(source#StringIO, dialect#NilClass, schema#NilClass, options#Hash)

  2. Csvlint::Validator.parse_extension(source#Tempfile) Csvlint::Validator.initialize(source#Tempfile, dialect#Hash, schema#NilClass, options#Hash)

  3. `Csvlint::Validator.initialize(source#NilClass, dialect#Hash, schema#NilClass, options#Hash) Csvlint::Validator.parse_extension(source#NilClass)

likely cause of fault is

validation = Validation.validate(self.url || self.csv, schema.try(:url), loaded_schema, dialect)

returning nil for both self.url and self.csv and the subsequent Validation.validate method having no rescue for it's io parameter equallying nil

def self.validate(io, schema_url = nil, schema = nil, dialect = nil)
quadrophobiac commented 9 years ago

The error is caused by nil being passed to self.validate for $arg io

This results in

validator = Csvlint::Validator.new( io, dialect, schema && schema.fields.empty? ? nil : schema )

receiving io as nil, which results in the@source instance variable within CSVLint Gem > validate.rb, causing the method validate to return the errors which are at the root of this issue

quadrophobiac commented 9 years ago

Comparison backtraces

#0  Csvlint::Validator.parse_extension(source#Tempfile) at /Users/stephenfortune/Documents/csvlint.rb/lib/csvlint/validate.rb:252
#1  Csvlint::Validator.initialize(source#Tempfile, dialect#Hash, schema#NilClass, options#Hash) at /Users/stephenfortune/Documents/csvlint.rb/lib/csvlint/validate.rb:34
#2  Class.new(*args) at /Users/stephenfortune/Documents/csvlint/app/models/validation.rb:35
#3  #<Class:Validation>.validate(io#Tempfile, schema_url#NilClass, schema#NilClass, dialect#Hash) at /Users/stephenfortune/Documents/csvlint/app/models/validation.rb:35
#4  Validation.update_validation(dialect#Hash) at /Users/stephenfortune/Documents/csvlint/app/models/validation.rb:158
 #5  ValidationController.update at /Users/stephenfortune/Documents/csvlint/app/controllers/validation_controller.rb:37

at this point self has a self.csv parameter

press revalidate button again crash

#0  Csvlint::Validator.parse_extension(source#NilClass) at /Users/stephenfortune/Documents/csvlint.rb/lib/csvlint/validate.rb:252
#1  Csvlint::Validator.initialize(source#NilClass, dialect#Hash, schema#NilClass, options#Hash) at /Users/stephenfortune/Documents/csvlint.rb/lib/csvlint/validate.rb:34
#2  Class.new(*args) at /Users/stephenfortune/Documents/csvlint/app/models/validation.rb:35
#3  #<Class:Validation>.validate(io#NilClass, schema_url#NilClass, schema#NilClass, dialect#Hash) at /Users/stephenfortune/Documents/csvlint/app/models/validation.rb:35
#4  Validation.update_validation(dialect#Hash) at /Users/stephenfortune/Documents/csvlint/app/models/validation.rb:158
#5  ValidationController.update at /Users/stephenfortune/Documents/csvlint/app/controllers/validation_controller.rb:37

Frame 5 is in validation controller, and in this state the csv_id has been set to nil either because it doesn't retreive the Mongo record correctly or the Validation object has been shorn of its csv_id parameter