From aee39333ee06d7d8447e92b99d2ef06c0d8aac3f Mon Sep 17 00:00:00 2001 From: Shaun Amott Date: Fri, 29 Jul 2011 22:59:32 +0000 Subject: [PATCH] - Decode patches in the PR body. - Detect base64 attachments (in the PR). - Grab the filename from UU patches. --- en/cgi/GnatsPR.pm | 12 ++++++++++-- en/cgi/GnatsPR/Section/Patch.pm | 24 ++++++++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/en/cgi/GnatsPR.pm b/en/cgi/GnatsPR.pm index 34923b190d..3012f70fdf 100644 --- a/en/cgi/GnatsPR.pm +++ b/en/cgi/GnatsPR.pm @@ -24,7 +24,7 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# $FreeBSD: www/en/cgi/GnatsPR.pm,v 1.2 2011/07/21 02:09:02 shaun Exp $ +# $FreeBSD: www/en/cgi/GnatsPR.pm,v 1.3 2011/07/29 20:37:43 shaun Exp $ #------------------------------------------------------------------------------ package GnatsPR; @@ -539,7 +539,12 @@ sub FindPatchStart # UUencoded file. Characteristics: # - Has header and footer. $$text =~ /^begin \d\d\d (.*)/m - and return {start => $-[0], type => 'uuencoded'}; + and return {start => $-[0], type => 'uuencoded', name => $1}; + + # Base64 encoded file. Characteristics: + # - Has header and footer. + $$text =~ /^begin-base64 \d\d\d (.*)/m + and return {start => $-[0], type => 'base64', name => $1}; return undef; } @@ -583,6 +588,9 @@ sub FindPatchEnd } elsif ($pi->{type} eq 'uuencoded') { $$text =~ /^end$/m and $pi->{size} = $+[0]; + } elsif ($pi->{type} eq 'base64') { + $$text =~ /^====$/m + and $pi->{size} = $+[0]; } if ($pi->{size} == 0) { diff --git a/en/cgi/GnatsPR/Section/Patch.pm b/en/cgi/GnatsPR/Section/Patch.pm index 00660e9d12..0b8e1664e0 100644 --- a/en/cgi/GnatsPR/Section/Patch.pm +++ b/en/cgi/GnatsPR/Section/Patch.pm @@ -24,11 +24,14 @@ # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # -# $FreeBSD$ +# $FreeBSD: www/en/cgi/GnatsPR/Section/Patch.pm,v 1.1 2011/07/20 22:23:23 shaun Exp $ #------------------------------------------------------------------------------ package GnatsPR::Section::Patch; +use MIME::Base64; # ports/converters/p5-MIME-Base64 +use Convert::UU qw(uudecode uuencode); # ports/converters/p5-Convert-UU + use strict; require 5.006; @@ -53,6 +56,8 @@ sub new my $self = { text => '', filename => 'patch.txt', + binary => 0, + encoded => 0, type => 'unknown' }; @@ -63,6 +68,17 @@ sub new $self->{filename} = $filename if $filename; $self->{type} = $type if $type; + $self->{filename} =~ '(?:\.gz|\.bz2|\.zip|\.tar)$' + and $self->{binary} = 1; + + if ($self->{type} eq 'uuencoded') { + $self->{encoded} = 1; + $self->{decoded_text} = uudecode($self->{text}); + } elsif ($self->{type} eq 'base64') { + $self->{encoded} = 1; + $self->{decoded_text} = decode_base64($self->{text}); + } + return $self; } @@ -97,7 +113,7 @@ sub size { my $self = shift; - return length($self->{text}); + return length($self->{encoded} ? $self->{decoded_text} : $self->{text}); } @@ -114,7 +130,7 @@ sub data { my $self = shift; - return $self->{text}; + return $self->{encoded} ? $self->{decoded_text} : $self->{text}; } @@ -165,7 +181,7 @@ sub isbinary { my $self = shift; - return 0; + return $self->{binary}; }