From: Gisle Aas Date: Tue, 13 May 2003 19:51:19 +0000 (-0700) Subject: Re: [PATCH] Sync up MIME-Base64 to latest on CPAN X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ea0e37e48a6e7942e23df67a0ae153e0f80bcbb3;p=p5sagit%2Fp5-mst-13.2.git Re: [PATCH] Sync up MIME-Base64 to latest on CPAN Message-ID: p4raw-id: //depot/perl@19523 --- diff --git a/ext/MIME/Base64/Base64.pm b/ext/MIME/Base64/Base64.pm index ebf94ba..26db209 100644 --- a/ext/MIME/Base64/Base64.pm +++ b/ext/MIME/Base64/Base64.pm @@ -1,5 +1,5 @@ # -# $Id: Base64.pm,v 2.28 2003/05/13 16:21:25 gisle Exp $ +# $Id: Base64.pm,v 2.29 2003/05/13 18:22:09 gisle Exp $ package MIME::Base64; @@ -137,7 +137,7 @@ require DynaLoader; @ISA = qw(Exporter DynaLoader); @EXPORT = qw(encode_base64 decode_base64); -$VERSION = '2.19'; +$VERSION = '2.20'; eval { bootstrap MIME::Base64 $VERSION; }; if ($@) { diff --git a/ext/MIME/Base64/Base64.xs b/ext/MIME/Base64/Base64.xs index d540f11..9cbf2b5 100644 --- a/ext/MIME/Base64/Base64.xs +++ b/ext/MIME/Base64/Base64.xs @@ -1,4 +1,4 @@ -/* $Id: Base64.xs,v 1.36 2003/05/13 16:21:25 gisle Exp $ +/* $Id: Base64.xs,v 1.37 2003/05/13 18:20:18 gisle Exp $ Copyright 1997-2003 Gisle Aas @@ -398,23 +398,31 @@ decode_qp(sv) } whitespace = 0; } - if (*str == '=' && (str + 2) < end && isxdigit(str[1]) && isxdigit(str[2])) { - char buf[3]; - str++; - buf[0] = *str++; - buf[1] = *str++; - buf[2] = '\0'; - *r++ = (char)strtol(buf, 0, 16); - } - else if (*str == '=' && (str + 1) < end && str[1] == '\n') { - str += 2; + if (*str == '=') { + if ((str + 2) < end && isxdigit(str[1]) && isxdigit(str[2])) { + char buf[3]; + str++; + buf[0] = *str++; + buf[1] = *str++; + buf[2] = '\0'; + *r++ = (char)strtol(buf, 0, 16); + } + else { + /* look for soft line break */ + char *p = str + 1; + while (p < end && (*p == ' ' || *p == '\t')) + p++; + if (p < end && *p == '\n') + str = p + 1; + else if ((p + 1) < end && *p == '\r' && *(p + 1) == '\n') + str = p + 2; + else + *r++ = *str++; /* give up */ + } } - else if (*str == '=' && (str + 2) < end && str[1] == '\r' && str[2] == '\n') { - str += 3; + else { + *r++ = *str++; } - else { - *r++ = *str++; - } } } if (whitespace) { diff --git a/ext/MIME/Base64/Changes b/ext/MIME/Base64/Changes index 24c31f0..143d31f 100644 --- a/ext/MIME/Base64/Changes +++ b/ext/MIME/Base64/Changes @@ -1,5 +1,14 @@ 2003-05-13 Gisle Aas + Release 2.20 + + decode_qp() recognize soft whitespace when there is whitespace + between the '=' and the '\n'. + + + +2003-05-13 Gisle Aas + Release 2.19 decode_qp() did eat up all trailing whitespace in the string decoded. diff --git a/ext/MIME/Base64/QuotedPrint.pm b/ext/MIME/Base64/QuotedPrint.pm index 08d3468..663031f 100644 --- a/ext/MIME/Base64/QuotedPrint.pm +++ b/ext/MIME/Base64/QuotedPrint.pm @@ -1,5 +1,5 @@ # -# $Id: QuotedPrint.pm,v 2.12 2003/05/13 16:21:25 gisle Exp $ +# $Id: QuotedPrint.pm,v 2.13 2003/05/13 18:22:09 gisle Exp $ package MIME::QuotedPrint; @@ -73,7 +73,7 @@ require Exporter; use Carp qw(croak); -$VERSION = "2.19"; +$VERSION = "2.20"; use MIME::Base64; # try to load XS version of encode_qp unless (defined &encode_qp) { diff --git a/ext/MIME/Base64/t/quoted-print.t b/ext/MIME/Base64/t/quoted-print.t index 884bebb..2c9d9ea 100644 --- a/ext/MIME/Base64/t/quoted-print.t +++ b/ext/MIME/Base64/t/quoted-print.t @@ -91,7 +91,7 @@ y. -- H. L. Mencken"], ["foo\t \n \t", "foo=09=20\n=20=09"], ); -$notests = @tests + 7; +$notests = @tests + 13; print "1..$notests\n"; $testno = 0; @@ -138,6 +138,24 @@ $testno++; print "ok $testno\n"; print "not " unless decode_qp("foo \n") eq "foo\n"; $testno++; print "ok $testno\n"; +print "not " unless decode_qp("foo = \t\x20\nbar\t\x20\n") eq "foo bar\n"; +$testno++; print "ok $testno\n"; + +print "not " unless decode_qp("foo = \t\x20\r\nbar\t\x20\r\n") eq "foo bar\n"; +$testno++; print "ok $testno\n"; + +print "not " unless decode_qp("foo = \t\x20\n") eq "foo "; +$testno++; print "ok $testno\n"; + +print "not " unless decode_qp("foo = \t\x20\r\n") eq "foo "; +$testno++; print "ok $testno\n"; + +print "not " unless decode_qp("foo = \t\x20y\r\n") eq "foo = \t\x20y\n"; +$testno++; print "ok $testno\n"; + +print "not " unless decode_qp("foo =xy\n") eq "foo =xy\n"; +$testno++; print "ok $testno\n"; + # Test with with alternative line break print "not " unless encode_qp("$x70!2345$x70\n", "***") eq "$x70!2345=***$x70***"; $testno++; print "ok $testno\n";