[Rt-commit] rt branch, 4.0/attachment-with-name-0, created. rt-4.0.1-300-g02f3bff
? sunnavy
sunnavy at bestpractical.com
Tue Aug 16 17:45:25 EDT 2011
The branch, 4.0/attachment-with-name-0 has been created
at 02f3bff1513fa0226ebbcae92ddcfc023c695fe8 (commit)
- Log -----------------------------------------------------------------
commit d1ba38b5f7c8a96e2febd1af2e1498f8f9ec0751
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Aug 17 04:57:01 2011 +0800
handle the edge case that filename is 0
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index ab2830f..801d2d1 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -1639,8 +1639,8 @@ sub MakeMIMEEntity {
if ( $args{'AttachmentFieldName'} ) {
my $cgi_object = $m->cgi_object;
-
- if ( my $filehandle = $cgi_object->upload( $args{'AttachmentFieldName'} ) ) {
+ my $filehandle = $cgi_object->upload( $args{'AttachmentFieldName'} );
+ if ( defined $filehandle && length $filehandle ) {
my ( @content, $buffer );
while ( my $bytesread = read( $filehandle, $buffer, 4096 ) ) {
diff --git a/share/html/Search/Bulk.html b/share/html/Search/Bulk.html
index bf87007..dc6b1db 100755
--- a/share/html/Search/Bulk.html
+++ b/share/html/Search/Bulk.html
@@ -237,7 +237,7 @@ foreach my $key (keys %ARGS) {
}
# store the uploaded attachment in session
-if ($ARGS{'Attach'}) { # attachment?
+if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
my $attachment = MakeMIMEEntity(
AttachmentFieldName => 'Attach'
);
diff --git a/share/html/SelfService/Display.html b/share/html/SelfService/Display.html
index 3a22aa5..49065d6 100755
--- a/share/html/SelfService/Display.html
+++ b/share/html/SelfService/Display.html
@@ -101,7 +101,7 @@ my @id = ( ref $id eq 'ARRAY' ) ? @{$id} : ($id);
my $Ticket = RT::Ticket->new( $session{'CurrentUser'} );
# store the uploaded attachment in session
-if ( $ARGS{'Attach'} ) { # attachment?
+if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
$session{'Attachments'} = {} unless defined $session{'Attachments'};
my $attachment = MakeMIMEEntity(
diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index fb70c2b..7f3a506 100755
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -381,7 +381,7 @@ foreach my $key (keys %ARGS) {
}
# store the uploaded attachment in session
-if ($ARGS{'Attach'}) { # attachment?
+if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
my $attachment = MakeMIMEEntity(
AttachmentFieldName => 'Attach'
);
diff --git a/share/html/Ticket/Elements/ShowAttachments b/share/html/Ticket/Elements/ShowAttachments
index 12490f7..786fdaa 100755
--- a/share/html/Ticket/Elements/ShowAttachments
+++ b/share/html/Ticket/Elements/ShowAttachments
@@ -104,7 +104,7 @@ $Attachments ||= $m->comp('FindAttachments', Ticket => $Ticket);
my %documents;
while ( my $attach = $Attachments->Next() ) {
- next unless ($attach->Filename());
+ next unless defined $attach->Filename && length $attach->Filename;
unshift( @{ $documents{ $attach->Filename } }, $attach );
}
diff --git a/share/html/Ticket/Elements/ShowTransactionAttachments b/share/html/Ticket/Elements/ShowTransactionAttachments
index ccf35fd..6caff7d 100644
--- a/share/html/Ticket/Elements/ShowTransactionAttachments
+++ b/share/html/Ticket/Elements/ShowTransactionAttachments
@@ -60,11 +60,12 @@ foreach my $message ( grep $_->__Value('Parent') == $Parent, @$Attachments ) {
);
my $size = $message->ContentLength;
+ my $name = defined $message->Filename && length $message->Filename ? $message->Filename : '';
if ( $size ) {
</%PERL>
<div class="downloadattachment">
-<a href="<% $AttachPath %>/<% $Transaction->Id %>/<% $message->Id %>/<% ($message->Filename ||'')| u%>"><&|/l&>Download</&> <% $message->Filename || loc('(untitled)') %></a>\
-% if ( $DownloadableHeaders && !$message->Filename && $message->ContentType =~ /text/ ) {
+<a href="<% $AttachPath %>/<% $Transaction->Id %>/<% $message->Id %>/<% $name | u%>"><&|/l&>Download</&> <% length $name ? $name : loc('(untitled)') %></a>\
+% if ( $DownloadableHeaders && ! length $name && $message->ContentType =~ /text/ ) {
/ <a href="<% $AttachPath %>/WithHeaders/<% $message->Id %>"><% loc('with headers') %></a>
% }
% $m->callback(CallbackName => 'AfterDownloadLinks', ARGSRef => \%ARGS, Ticket => $Ticket, Transaction => $Transaction, Attachment => $message);
@@ -141,6 +142,7 @@ my $size_to_str = sub {
my $render_attachment = sub {
my $message = shift;
+ my $name = defined $message->Filename && length $message->Filename ? $message->Filename : '';
# if it has a content-disposition: attachment, don't show inline
my $disposition = $message->GetHeader('Content-Disposition');
@@ -158,7 +160,7 @@ my $render_attachment = sub {
$m->out('<p>'. loc( 'Message body is not shown because sender requested not to inline it.' ) .'</p>');
return;
}
- elsif ( $message->Filename && RT->Config->Get('SuppressInlineTextFiles', $session{'CurrentUser'} ) ) {
+ elsif ( length $name && RT->Config->Get('SuppressInlineTextFiles', $session{'CurrentUser'} ) ) {
$m->out('<p>'. loc( 'Text file is not shown because it is disabled in preferences.' ) .'</p>');
return;
}
@@ -214,8 +216,7 @@ my $render_attachment = sub {
);
require HTML::Quoted;
- $content = HTML::Quoted->extract($content)
- unless $message->Filename;
+ $content = HTML::Quoted->extract($content) unless length $name;
$m->comp(
'ShowMessageStanza',
@@ -233,7 +234,7 @@ my $render_attachment = sub {
# if it's a text/plain show the body
elsif ( $message->ContentType =~ m{^(text|message)}i ) {
- unless ( $message->Filename ) {
+ unless ( length $name ) {
eval { require Text::Quoted; $content = Text::Quoted::extract($content); };
if ($@) { $RT::Logger->warning( "Text::Quoted failed: $@" ) }
}
@@ -255,7 +256,7 @@ my $render_attachment = sub {
return;
}
- my $filename = $message->Filename || loc('(untitled)');
+ my $filename = length $name ? $name : loc('(untitled)');
$m->out('<img'
. ' alt="'
. $filename
diff --git a/share/html/Ticket/ModifyAll.html b/share/html/Ticket/ModifyAll.html
index 9416652..8685da0 100755
--- a/share/html/Ticket/ModifyAll.html
+++ b/share/html/Ticket/ModifyAll.html
@@ -161,7 +161,7 @@ foreach my $key (keys %ARGS) {
}
# store the uploaded attachment in session
-if ($ARGS{'Attach'}) { # attachment?
+if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
my $attachment = MakeMIMEEntity(
AttachmentFieldName => 'Attach'
);
diff --git a/share/html/Ticket/Update.html b/share/html/Ticket/Update.html
index 0c41491..fb86b25 100755
--- a/share/html/Ticket/Update.html
+++ b/share/html/Ticket/Update.html
@@ -251,7 +251,7 @@ foreach my $key (keys %ARGS) {
}
# store the uploaded attachment in session
-if ($ARGS{'Attach'}) { # attachment?
+if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
my $attachment = MakeMIMEEntity(
AttachmentFieldName => 'Attach'
);
diff --git a/share/html/m/ticket/create b/share/html/m/ticket/create
index 5ddb6b8..0bfdf17 100644
--- a/share/html/m/ticket/create
+++ b/share/html/m/ticket/create
@@ -174,7 +174,7 @@ foreach my $key (keys %ARGS) {
}
# store the uploaded attachment in session
-if ($ARGS{'Attach'}) { # attachment?
+if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
my $attachment = MakeMIMEEntity(
AttachmentFieldName => 'Attach'
);
diff --git a/share/html/m/ticket/reply b/share/html/m/ticket/reply
index 4aadfe3..895dd9a 100644
--- a/share/html/m/ticket/reply
+++ b/share/html/m/ticket/reply
@@ -170,7 +170,7 @@ foreach my $key (keys %ARGS) {
}
# store the uploaded attachment in session
-if ($ARGS{'Attach'}) { # attachment?
+if ( defined $ARGS{'Attach'} && length $ARGS{'Attach'} ) { # attachment?
my $attachment = MakeMIMEEntity(
AttachmentFieldName => 'Attach'
);
commit a5f81f29e6369c0ea89909c702fd64242362c68f
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Aug 17 05:09:25 2011 +0800
test the edge case where att name is 0
diff --git a/t/web/attachment-with-name-0 b/t/web/attachment-with-name-0
new file mode 100644
index 0000000..a91db52
--- /dev/null
+++ b/t/web/attachment-with-name-0
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+
+use RT::Test tests => 8;
+my ( $baseurl, $m ) = RT::Test->started_ok;
+ok $m->login, 'logged in as root';
+
+use File::Spec;
+use File::Temp 'tempdir';
+
+my $tmpdir = tempdir( DIR => $RT::VarPath, CLEANUP => 1 );
+my $file = File::Spec->catfile( $tmpdir, 0 );
+open my $fh, '>', $file or die $!;
+print $fh 'foobar';
+close $fh;
+
+$m->get_ok( '/Ticket/Create.html?Queue=1' );
+
+$m->submit_form(
+ form_number => 3,
+ fields => { Subject => 'test att 0', Content => 'test', Attach => $file },
+);
+$m->content_like( qr/Ticket \d+ created/i, 'created the ticket' );
+$m->follow_link_ok( { text => 'Download 0' } );
+$m->content_contains( 'foobar', 'file content' );
commit 02f3bff1513fa0226ebbcae92ddcfc023c695fe8
Author: sunnavy <sunnavy at bestpractical.com>
Date: Wed Aug 17 05:31:38 2011 +0800
cleanup
diff --git a/t/web/attachment_encoding.t b/t/web/attachment_encoding.t
index 2fe8200..1901dbf 100644
--- a/t/web/attachment_encoding.t
+++ b/t/web/attachment_encoding.t
@@ -17,7 +17,6 @@ diag 'test without attachments' if $ENV{TEST_VERBOSE};
{
$m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );
- $m->form_name('TicketModify');
$m->submit_form(
form_number => 3,
fields => { Subject => 'æ é¢', Content => 'æµè¯' },
@@ -42,10 +41,12 @@ diag 'test without attachments' if $ENV{TEST_VERBOSE};
diag 'test with attachemnts' if $ENV{TEST_VERBOSE};
-{
+use File::Temp 'tempdir';
+my $tmpdir = tempdir( DIR => $RT::VarPath, CLEANUP => 1 );
+{
my $file =
- File::Spec->catfile( File::Spec->tmpdir, encode_utf8 'é件.txt' );
+ File::Spec->catfile( $tmpdir, encode_utf8 'é件.txt' );
open( my $fh, '>', $file ) or die $!;
binmode $fh, ':utf8';
print $fh 'é件';
@@ -53,7 +54,6 @@ diag 'test with attachemnts' if $ENV{TEST_VERBOSE};
$m->get_ok( $baseurl . '/Ticket/Create.html?Queue=1' );
- $m->form_name('TicketModify');
$m->submit_form(
form_number => 3,
fields => { Subject => 'æ é¢', Content => 'æµè¯', Attach => $file },
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list