Re: bug? in URI::Escape::uri_unescape 3.13 in list context

Gisle Aas (gisle@activestate.com)
16 Aug 2000 20:50:54 +0200


Nicholas Clark <nick@ccl4.org> writes:

> The URI-1.08 README suggests that bug reports should be sent here.

A good idea!

> However, for list context with multiple arguments one enters the if clause,
> and the return value is the map of s///g in list context, which gives the
> number of substitutions:
> 
> /usr/bin/perl -MURI::Escape -wle 'foreach (@ARGV) {@foo= uri_unescape ($_,$_); print $foo[0]}' 1 2 '%33' 4 '%7E%21'

It was clearly bursted.  But the documentation did not actually tell
you that you could pass it multiple arguments either :-)

> This would appear to be a bug. The following would fix it:
> 
> sub uri_unescape
> {
>     # Note from RFC1630:  "Sequences which start with a percent sign
>     # but are not followed by two hexadecimal characters are reserved
>     # for future extension"
>     my $str = shift;
>     if (@_ && wantarray) {
> 	# not executed for the common case of a single argument
> 	my @str = ($str, @_);  # need to copy
> 	foreach (@str) {
> 	  s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg
> 	}
> 	return @str;
>     }
>     $str =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
>     $str;
> }

Thanks!  Applied.

> Ideally should there be a regression test?

True.  I even made one up just now.  It will be in the next release.
Thanks again!

Regards,
Gisle