Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the URI-Encode CPAN distribution.

Report information
The Basics
Id: 70628
Status: resolved
Priority: 0/
Queue: URI-Encode

People
Owner: MITHUN [...] cpan.org
Requestors: david [...] dbooth.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: (no value)
Fixed in: (no value)



Subject: 0 argument erroneously returns undef
When the string "0" is passed to the encode method, undef is returned instead of "0". By looking at the code I can see that the same bug also exists in the decode method. Sample code that demonstrates the bug: use URI::Encode qw(uri_encode uri_decode); my $s = "0"; my $encoded = uri_encode($s, 1); print "s: $s encoded: $encoded\n"; To correct the bug, the third lines of sub encode and sub decode should be changed from: return unless $url; to: return $url unless $url;
From: david [...] dbooth.org
On Tue Aug 30 22:08:47 2011, http://dbooth.idproxy.net/ wrote: Show quoted text
> When the string "0" is passed to the encode method, undef is returned > instead of "0". By looking at the code I can see that the same bug also > exists in the decode method. > > Sample code that demonstrates the bug: > > use URI::Encode qw(uri_encode uri_decode); > my $s = "0"; > my $encoded = uri_encode($s, 1); > print "s: $s encoded: $encoded\n"; > > To correct the bug, the third lines of sub encode and sub decode should > be changed from: > > return unless $url; > > to: > > return $url unless $url;
P.S. A workaround is to use the original value if it tests false (undef, 0 or ""): my $encoded = uri_encode($s, 1); $encoded = $s if !$s; or: my $decoded = uri_decode($encoded); $decoded = $encoded if !$decoded;
Fixed in 0.04. Thanks!