From: jisraelson@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:65597] [ruby-trunk - Bug #10364] [Open] Malformed CSV Header Causes NoMethodError
Date: Fri, 10 Oct 2014 15:53:13 +0000 [thread overview]
Message-ID: <redmine.issue-10364.20141010155313.9d667e892ab60113@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-10364.20141010155313@ruby-lang.org
Issue #10364 has been reported by Jon Israelson.
----------------------------------------
Bug #10364: Malformed CSV Header Causes NoMethodError
https://bugs.ruby-lang.org/issues/10364
* Author: Jon Israelson
* Status: Open
* Priority: Normal
* Assignee:
* Category:
* Target version:
* ruby -v: ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-darwin13.0]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN
----------------------------------------
The method CSV#readline raises a "NoMethodError: undefined method 'encode' for nil:NilClass" exception when the CSV file's header row contains a trailing delimiter (a comma in my case). The following CSV data can be used to recreate this error:
~~~
col1,col2,
1,2
3,4
~~~
The resulting stack trace:
~~~
csv.rb:993:in `block in <class:CSV>'
csv.rb:2175:in `[]'
csv.rb:2175:in `block (2 levels) in convert_fields'
csv.rb:2173:in `each'
csv.rb:2173:in `block in convert_fields'
csv.rb:2172:in `map'
csv.rb:2172:in `with_index'
csv.rb:2172:in `convert_fields'
csv.rb:2213:in `parse_headers'
csv.rb:1887:in `block in shift'
csv.rb:1779:in `loop'
csv.rb:1779:in `shift'
~~~
Assuming that the header row is considered malformed (IMHO it is), it seems that it would be better to raise a CSV::MalformedCSVError exception, which can be more easily handled.
--
https://bugs.ruby-lang.org/
next parent reply other threads:[~2014-10-10 16:09 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <redmine.issue-10364.20141010155313@ruby-lang.org>
2014-10-10 15:53 ` jisraelson [this message]
2014-10-13 7:41 ` [ruby-core:65651] [ruby-trunk - Bug #10364] [Assigned] Malformed CSV Header Causes NoMethodError shibata.hiroshi
2014-11-30 6:56 ` [ruby-core:66585] [ruby-trunk - Bug #10364] " jrodrigosm
2018-03-08 7:34 ` [ruby-core:86028] [Ruby trunk Bug#10364] " mame
2018-03-31 14:26 ` [ruby-core:86415] [Ruby trunk Bug#10364][Rejected] " kou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.issue-10364.20141010155313.9d667e892ab60113@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).