[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [sup-devel] Mysterious nil errors
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