From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.86.87.8 with SMTP id k8cs25628fgb; Wed, 10 Mar 2010 09:40:28 -0800 (PST) Received: by 10.224.94.197 with SMTP id a5mr1245854qan.5.1268242827945; Wed, 10 Mar 2010 09:40:27 -0800 (PST) Return-Path: Received: from rubyforge.org (rubyforge.org [205.234.109.19]) by mx.google.com with ESMTP id 5si19280648qwg.23.2010.03.10.09.40.27; Wed, 10 Mar 2010 09:40:27 -0800 (PST) Received-SPF: pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) client-ip=205.234.109.19; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 205.234.109.19 as permitted sender) smtp.mail=sup-devel-bounces@rubyforge.org Received: from rubyforge.org (rubyforge.org [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 6468F18582F3; Wed, 10 Mar 2010 12:40:27 -0500 (EST) Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU [18.9.25.12]) by rubyforge.org (Postfix) with ESMTP id 373D118582DA for ; Wed, 10 Mar 2010 12:40:20 -0500 (EST) X-AuditID: 1209190c-b7c00ae000000995-85-4b97d9842895 Received: from mailhub-auth-1.mit.edu (MAILHUB-AUTH-1.MIT.EDU [18.9.21.35]) by dmz-mailsec-scanner-1.mit.edu (Symantec Brightmail Gateway) with SMTP id C2.00.02453.489D79B4; Wed, 10 Mar 2010 12:40:20 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id o2AHeK1q011224 for ; Wed, 10 Mar 2010 12:40:20 -0500 Received: from localhost (EZYANG.MIT.EDU [18.243.1.50]) (authenticated bits=0) (User authenticated as ezyang@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id o2AHeJ3n011257 for ; Wed, 10 Mar 2010 12:40:20 -0500 (EST) From: "Edward Z. Yang" To: sup-devel In-reply-to: <1268241639-sup-9685@zyrg.net> References: <1268196562-sup-1692@ezyang> <1268241639-sup-9685@zyrg.net> Date: Wed, 10 Mar 2010 12:40:19 -0500 Message-Id: <1268242549-sup-1852@ezyang> User-Agent: Sup/git X-Brightmail-Tracker: AAAAAQCq+Kk= Subject: Re: [sup-devel] Mysterious nil errors X-BeenThere: sup-devel@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Sup developer discussion List-Id: Sup developer discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-devel-bounces@rubyforge.org Errors-To: sup-devel-bounces@rubyforge.org 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