Skip Menu |

This queue is for tickets about the XML-Namespace CPAN distribution.

Report information
The Basics
Id: 86559
Status: new
Priority: 0/
Queue: XML-Namespace

People
Owner: Nobody in particular
Requestors: gwilliams [...] cpan.org
Cc:
AdminCc:

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



Subject: uri method checks for truth, not definedness
The uri method in XML::Namespace attempts to use the empty string as a default in cases where no local part is supplied. Unfortunately, the code tests for truth: my $path = shift || ''; This breaks for cases where the function argument evaluates to a false value (such as '0'). Instead, the function should be testing for definedness: my $path = shift; unless (defined($path)) { $path = ''; } The attached patch does just this, and adds a test case.
Subject: xml-namespace.patch
Only in XML-Namespace-0.02.new/: .DS_Store diff -ru XML-Namespace-0.02.orig/lib/XML/Namespace.pm XML-Namespace-0.02.new/lib/XML/Namespace.pm --- XML-Namespace-0.02.orig/lib/XML/Namespace.pm 2005-08-22 17:06:55.000000000 +0300 +++ XML-Namespace-0.02.new/lib/XML/Namespace.pm 2013-06-29 13:01:10.000000000 +0300 @@ -85,7 +85,10 @@ sub uri { my $self = shift; - my $path = shift || ''; + my $path = shift; + unless (defined($path)) { + $path = ''; + } return "$$self$path"; } diff -ru XML-Namespace-0.02.orig/t/namespace.t XML-Namespace-0.02.new/t/namespace.t --- XML-Namespace-0.02.orig/t/namespace.t 2005-08-22 16:52:21.000000000 +0300 +++ XML-Namespace-0.02.new/t/namespace.t 2013-06-29 13:03:10.000000000 +0300 @@ -12,7 +12,7 @@ use warnings; use lib qw( ./lib ../lib ); use XML::Namespace; -use Test::More tests => 10; +use Test::More tests => 11; my $xsd = 'http://www.w3.org/2001/XMLSchema#'; my $rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'; @@ -74,3 +74,13 @@ XML::Namespace->import( foo => 'http://myfoo.com/' ); is( foo()->hello, 'http://myfoo.com/hello', 'hello foo' ); + + +#------------------------------------------------------------------------ +# test for proper handling of values that evaluate as false +#------------------------------------------------------------------------ + +use XML::Namespace; + +my $ex = XML::Namespace->new('http://example.org/'); +is( $ex->uri('0'), 'http://example.org/0', 'false-valued local part' );