Skip Menu |
 

This queue is for tickets about the MIME-tools CPAN distribution.

Report information
The Basics
Id: 71041
Status: resolved
Priority: 0/
Queue: MIME-tools

People
Owner: dfs+pause [...] roaringpenguin.com
Requestors: ais523 [...] bham.ac.uk
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 5.502
Fixed in: (no value)



Subject: Header parsing fails with misleading error message with unusual $\ values (particularly newline)
When $\ has a nonstandard value, MIME::Parser::process_header ends up writing out stray $\s to the internal $headstr scalar (I couldn't quite track down where this was happening, but read_chunk seems plausible). As a result, the resulting header can't be parsed. This is particularly confusing with $\ set to \n (probably the most common non-null value), because the leading newline is interpreted as a zero-length header, which MIME::Parser interprets as an error in parsing (because not the whole header was parsed), giving an error message saying that the erroneous line is the line before the first line. Fixing this is likely a simple matter of a "local $\" somewhere near the start of process_header, and would probably be faster than documenting the restriction. Information common in bug reports that is almost certainly irrelevant in this case: $ perl -v This is perl, v5.10.1 (*) built for i486-linux-gnu-thread-multi $ uname -a Linux desert 2.6.32-34-generic #77-Ubuntu SMP Tue Sep 13 19:40:53 UTC 2011 i686 GNU/Linux To reproduce, set $\ to \n, then try to parse any message with at least one header line.
Subject: Re: [rt.cpan.org #71041] Header parsing fails with misleading error message with unusual $\ values (particularly newline)
Date: Wed, 21 Sep 2011 10:04:12 -0400
To: bug-MIME-tools [...] rt.cpan.org
From: "David F. Skoll" <dfs [...] roaringpenguin.com>
Download (untitled) / with headers
text/plain 1.2k
Hi, Thanks for your bug report. I've made the following change which will appear in the next release. Please confirm that the patch below fixes the problem for you. Regards, David. diff --git a/lib/MIME/Parser.pm b/lib/MIME/Parser.pm index 2047bd2..4735a76 100644 --- a/lib/MIME/Parser.pm +++ b/lib/MIME/Parser.pm @@ -1153,6 +1153,7 @@ sub parse { my $entity; local $/ = "\n"; ### just to be safe + local $\ = undef; # CPAN ticket #71041 $self->init_parse; $entity = $self->process_part($in, undef); ### parse! diff --git a/t/ticket-71041.t b/t/ticket-71041.t new file mode 100644 index 0000000..519783b --- /dev/null +++ b/t/ticket-71041.t @@ -0,0 +1,24 @@ +use Test::More tests => 1; + +use MIME::Parser; + +my $parser = MIME::Parser->new(); +$parser->output_to_core(1); + +my $message = <<'EOF'; +From: <devnull@example.org> +To: <devnull@example.com> +Subject: Ticket #71041 test +Message-Id: <cheese@burger.org> +MIME-Version: 1.0 +Content-Type: text/plain + +This should parse properly. +EOF + +# Set $\ to something wacky +$\ = "\n"; + +my $entity = $parser->parse_data($message); +my $head = $entity->head; +is ($head->get('From'), "<devnull\@example.org>\n", 'Header was parsed as expected');
From: ais523 [...] bham.ac.uk
Download (untitled) / with headers
text/plain 305b
On Wed Sep 21 10:04:25 2011, dfs@roaringpenguin.com wrote: Show quoted text
> Hi, > > Thanks for your bug report. I've made the following change which will > appear in the next release. Please confirm that the patch below fixes > the problem for you.
I can confirm that the patch fixes the problem. Thanks for the fix!
Download (untitled) / with headers
text/plain 108b
Hi, I have just uploaded MIME-tools-5.503 to CPAN, which I believe resolves this ticket. Regards, David.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.