Base64 data: URLs vs url encoding

Hi,

print URI->new('data:;base64,QmpvZXJu')->data;
print URI->new('data:;base64,%51%6D%70%76%5A%58%4A%75')->data;

I think this should both print "Bjoern", but in the second case the
module returns garbage (URI 1.35).

regards,
--
Björn Höhrmann · mailto:bjoern [at] hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
derhoermi [ Mi, 19 April 2006 08:56 ] [ ID #1280878 ]

Re: Base64 data: URLs vs url encoding

Bjoern Hoehrmann <derhoermi [at] gmx.net> writes:

> Hi,
>
> print URI->new('data:;base64,QmpvZXJu')->data;
> print URI->new('data:;base64,%51%6D%70%76%5A%58%4A%75')->data;
>
> I think this should both print "Bjoern", but in the second case the
> module returns garbage (URI 1.35).

Thanks for your report. I've applied the following patch to fix this
bug:

Index: URI/data.pm
============================================================ =======
RCS file: /cvsroot/libwww-perl/uri/URI/data.pm,v
retrieving revision 4.4
diff -u -p -r4.4 data.pm
--- URI/data.pm 14 Jan 2004 13:33:44 -0000 4.4
+++ URI/data.pm 19 Apr 2006 11:01:01 -0000
[at] [at] -55,7 +55,8 [at] [at] sub data
$self->opaque("$enc,$new");
}
return unless defined wantarray;
- return $base64 ? decode_base64($data) : uri_unescape($data);
+ $data = uri_unescape($data);
+ return $base64 ? decode_base64($data) : $data;
}

# I could not find a better way to interpolate the tr/// chars from
Index: t/data.t
============================================================ =======
RCS file: /cvsroot/libwww-perl/uri/t/data.t,v
retrieving revision 1.4
diff -u -p -r1.4 data.t
--- t/data.t 5 Aug 2003 15:27:49 -0000 1.4
+++ t/data.t 19 Apr 2006 11:01:01 -0000
[at] [at] -9,7 +9,7 [at] [at] if ($ [at] ) {
exit;
}

-print "1..21\n";
+print "1..22\n";

use URI;

[at] [at] -106,3 +106,5 [at] [at] $old = $u->data("new");
print "not " unless $old eq "" && $u eq "data:bar%2Cb%E5z,new";
print "ok 21\n";

+print "not " unless URI->new('data:;base64,%51%6D%70%76%5A%58%4A%75')->data eq "Bjoern";
+print "ok 22\n";
gisle [ Mi, 19 April 2006 13:03 ] [ ID #1280879 ]
Perl » perl.libwww » Base64 data: URLs vs url encoding

Vorheriges Thema: ConnCache not been used in LWP::UserAgent
Nächstes Thema: Large-scale spidering