Skip Menu |

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

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

People
Owner: dfs+pause [...] roaringpenguin.com
Requestors: KevinAMcGrail-CPAN [...] mcgrail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 5.506
Fixed in: (no value)



Subject: mime_attr doesn't parse filenames correctly in certain formats
MIME attributes such as this example: Content-Transfer-Encoding: base64 Content-Type: application/zip; name=check_No_9355-675.zip Content-Disposition: attachment; filename=check.zip size=16875 When using mime_attr such as $entity->head->mime_attr('Content-Disposition.filename'); returns "check.zip size=16887" as the filename instead of "check.zip". I do not know if the attributes are properly formatted, whether a semi-colon should be expected, etc. but I think this presents a real world case for consideration. Regards, KAM
Subject: Re: [rt.cpan.org #105455] mime_attr doesn't parse filenames correctly in certain formats
Date: Tue, 23 Jun 2015 21:40:09 -0400
To: bug-MIME-tools [...] rt.cpan.org
From: Dianne Skoll <dfs [...] roaringpenguin.com>
Hi, Kevin, Yes, a MIME attribute = value pair says that a value must either be a quoted-string or a token. So MIME::tools should return check.zip as the filename and not "check.zip size=16887" I'll look into fixing this. Regards, Dianne.
Subject: Re: [rt.cpan.org #105455] mime_attr doesn't parse filenames correctly in certain formats
Date: Wed, 24 Jun 2015 10:16:16 -0400
To: bug-MIME-tools [...] rt.cpan.org
From: Dianne Skoll <dfs [...] roaringpenguin.com>
Hi, Kevin, This patch seems to work for me. Please give it a try. Regards, Dianne. commit 16e52b624dd70714cbbb05fcca466c0c788478e8 Author: Dianne Skoll <dfs@roaringpenguin.com> Date: Wed Jun 24 10:14:49 2015 -0400 Fix for RT CPAN #105455 diff --git a/lib/MIME/Field/ParamVal.pm b/lib/MIME/Field/ParamVal.pm index 19d8b45..1a9cbd2 100644 --- a/lib/MIME/Field/ParamVal.pm +++ b/lib/MIME/Field/ParamVal.pm @@ -103,7 +103,7 @@ my $TSPECIAL = '()<>@,;:\</[]?="'; #" Fix emacs highlighting... -my $TOKEN = '[^ \x00-\x1f\x80-\xff' . "\Q$TSPECIAL\E" . ']+'; +my $TOKEN = '[^\x00-\x1f\x80-\xff' . "\Q$TSPECIAL\E" . ']+'; my $QUOTED_STRING = '"([^\\\\"]*(?:\\\\.(?:[^\\\\"]*))*)"'; @@ -251,6 +251,9 @@ sub parse_params { # Strip leading/trailing whitespace from badtoken $badtoken =~ s/^\s+//; $badtoken =~ s/\s+\z//; + + # Strip anything after a space - CPAN RT #105455 + $badtoken =~ s/\s.*//; } $val = defined($qstr) ? $qstr : (defined($enctoken) ? $enctoken : diff --git a/t/ParamVal.t b/t/ParamVal.t index 824cd38..4990ff3 100644 --- a/t/ParamVal.t +++ b/t/ParamVal.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 9; use MIME::Field::ContType; use MIME::WordDecoder; @@ -34,3 +34,20 @@ use Encode; is( encode('utf8', $wd->decode($field->param('answer'))), $expected, 'answer param was unpacked correctly'); } + +# Test for CPAN RT #105455 +{ + my $header = 'attachment; filename=wookie.zip size=3'; + + my $field = Mail::Field->new('Content-type'); + $field->parse( $header ); + is( $field->param('_'), 'attachment', 'Got body of header'); + is ($field->param('filename'), 'wookie.zip', 'Got correct filename'); + + $header = 'attachment; filename="wookie.zip size=3"'; + + $field = Mail::Field->new('Content-type'); + $field->parse( $header ); + is( $field->param('_'), 'attachment', 'Got body of header'); + is ($field->param('filename'), 'wookie.zip size=3', 'Got correct filename'); +}
On Wed Jun 24 10:16:30 2015, dfs@roaringpenguin.com wrote: Show quoted text
> Hi, Kevin, > > This patch seems to work for me. Please give it a try. > > Regards, > > Dianne.
Looks good so far. It correctly identifies the edge case identified previously. Regards, KAM
Subject: Re: [rt.cpan.org #105455] mime_attr doesn't parse filenames correctly in certain formats
Date: Wed, 24 Jun 2015 14:25:10 -0400
To: bug-MIME-tools [...] rt.cpan.org
From: Dianne Skoll <dfs [...] roaringpenguin.com>
Hi, Kevin, Show quoted text
> Looks good so far. It correctly identifies the edge case identified > previously.
OK. I've actually settled on the patch below as a more comprehensive fix. It's against the original MIME-tools, not against the previous patch. Regards, Dianne. diff --git a/lib/MIME/Field/ParamVal.pm b/lib/MIME/Field/ParamVal.pm index 19d8b45..883285b 100644 --- a/lib/MIME/Field/ParamVal.pm +++ b/lib/MIME/Field/ParamVal.pm @@ -251,6 +251,13 @@ sub parse_params { # Strip leading/trailing whitespace from badtoken $badtoken =~ s/^\s+//; $badtoken =~ s/\s+\z//; + + # Only keep token parameters in badtoken; + # cut it off at the first non-token char. CPAN RT #105455 + $badtoken =~ /^($TOKEN)*/; + $badtoken = $1; + # Cut it off at first whitespace too + $badtoken =~ s/\s.*//; } $val = defined($qstr) ? $qstr : (defined($enctoken) ? $enctoken : diff --git a/t/ParamVal.t b/t/ParamVal.t index 824cd38..4990ff3 100644 --- a/t/ParamVal.t +++ b/t/ParamVal.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 9; use MIME::Field::ContType; use MIME::WordDecoder; @@ -34,3 +34,20 @@ use Encode; is( encode('utf8', $wd->decode($field->param('answer'))), $expected, 'answer param was unpacked correctly'); } + +# Test for CPAN RT #105455 +{ + my $header = 'attachment; filename=wookie.zip size=3'; + + my $field = Mail::Field->new('Content-type'); + $field->parse( $header ); + is( $field->param('_'), 'attachment', 'Got body of header'); + is ($field->param('filename'), 'wookie.zip', 'Got correct filename'); + + $header = 'attachment; filename="wookie.zip size=3"'; + + $field = Mail::Field->new('Content-type'); + $field->parse( $header ); + is( $field->param('_'), 'attachment', 'Got body of header'); + is ($field->param('filename'), 'wookie.zip size=3', 'Got correct filename'); +}
RT-Send-CC: dfs [...] roaringpenguin.com
On Wed Jun 24 14:25:20 2015, dfs@roaringpenguin.com wrote: Show quoted text
> OK. I've actually settled on the patch below as a more comprehensive > fix. It's against the original MIME-tools, not against the previous > patch.
Also looks good. regards, KAM