From: "Edward Z. Yang" <ezyang@MIT.EDU>
To: sup-devel <sup-devel@rubyforge.org>
Subject: Re: [sup-devel] Mysterious nil errors
Date: Wed, 10 Mar 2010 12:40:19 -0500 [thread overview]
Message-ID: <1268242549-sup-1852@ezyang> (raw)
In-Reply-To: <1268241639-sup-9685@zyrg.net>
Excerpts from Rich Lane's message of Wed Mar 10 12:24:12 -0500 2010:
> Excerpts from Edward Z. Yang's message of 2010-03-09 23:50:23 -0500:
> > - content_type = (m.header.content_type || "application/unknown").downcase # sometimes RubyMail gives us nil
> > + content_type = (m.header["content_type"] && m.header.content_type || "application/unknown").downcase # sometimes RubyMail gives us nil
>
> Could you explain why these changes help? What's the return value of the
> [] call versus the method call?
Sure! We turn our heads to exhibit 1: The rmail code that implements m.header.content_type
def content_type(default = nil)
if value = self['content-type']
value.strip.split(/\s*;\s*/)[0].downcase
else
if block_given?
yield
else
default
end
end
end
This code takes "text/plain; charset=utf-8" and ensures that only "text/plain"
is returned. But what if self['content-type'] is empty? Then we call split
on an empty string...
irb(main):001:0> "".strip.split(/\s*;\s*/)
=> []
Oops; the zero indexing fails.
Actually, the patch is buggy; I should be testing for content-type instead. :-)
Cheers,
Edward
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel
next prev parent reply other threads:[~2010-03-10 17:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-10 4:50 Edward Z. Yang
2010-03-10 4:52 ` Edward Z. Yang
2010-03-10 6:43 ` Tero Tilus
2010-03-10 17:24 ` Rich Lane
2010-03-10 17:40 ` Edward Z. Yang [this message]
2010-03-10 17:59 ` Rich Lane
2010-03-10 18:06 ` Edward Z. Yang
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-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1268242549-sup-1852@ezyang \
--to=ezyang@mit.edu \
--cc=sup-devel@rubyforge.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