Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

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

Report information
The Basics
Id: 73801
Status: new
Priority: 0/
Queue: XML-Stream

People
Owner: Nobody in particular
Requestors: whynot [...] pozharski.name
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.23_06
Fixed in: (no value)



Subject: handling attrib='0'
Hopefully I've managed to show in attached diffs that if element has attribute set to '0' than it's handling is broken. XML-Stream, as of 1.23.6, returns empty string. What is obvious Perl-FALSE but it's not literal '0'. However, I suppose, it should (in fact, for sake of IBB -- I need that '0'). 'nil-is-defined.diff' fixes accessing attributes by some high and intermediate level calls (underlying 'get_attrib' looks OK). 'queries-are-broken-too.diff' adds expected (I believe, it's expected) behaviour for 'elem[@attrib="0"]' and 'elem/@attrib' queries. The latter is more intrusive because just patching 'Op.pm' adds quiet a few false positives in other queries in 'xpath.t'. In either case, any diff is test-suite clean for me (perl: 5.10.1) I hope, there will be a brave soul some day who will make sure that 'elem[@attrib=""]' works as expected too. I just need nils.
Subject: queries-are-broken-too.diff
diff -ur nil-is-defined/lib/XML/Stream/Node.pm queries-are-broken-too/lib/XML/Stream/Node.pm --- nil-is-defined/lib/XML/Stream/Node.pm 2012-01-04 00:38:56.000000000 +0200 +++ queries-are-broken-too/lib/XML/Stream/Node.pm 2012-01-04 22:18:51.000000000 +0200 @@ -838,7 +838,7 @@ # a "value", or [] for "tree", "value array", and "tree array". #------------------------------------------------------------------------- return 0 if ($type eq "existence"); - return "" if ($type eq "value"); + return if ($type eq "value"); return []; } diff -ur nil-is-defined/lib/XML/Stream/Tree.pm queries-are-broken-too/lib/XML/Stream/Tree.pm --- nil-is-defined/lib/XML/Stream/Tree.pm 2011-07-19 19:49:32.000000000 +0300 +++ queries-are-broken-too/lib/XML/Stream/Tree.pm 2012-01-04 23:06:27.000000000 +0200 @@ -579,7 +579,7 @@ # a "value", or [] for "tree", "value array", and "tree array". #--------------------------------------------------------------------------- return 0 if ($type eq "existence"); - return "" if ($type eq "value"); + return if ($type eq "value"); return []; } diff -ur nil-is-defined/lib/XML/Stream/XPath/Op.pm queries-are-broken-too/lib/XML/Stream/XPath/Op.pm --- nil-is-defined/lib/XML/Stream/XPath/Op.pm 2012-01-04 16:10:23.000000000 +0200 +++ queries-are-broken-too/lib/XML/Stream/XPath/Op.pm 2012-01-04 17:47:30.000000000 +0200 @@ -529,7 +529,7 @@ { if ($self->{VALUE} ne "*") { - if (&XML::Stream::GetXMLData("value",$elem,"",$self->{VALUE})) + if (defined &XML::Stream::GetXMLData("value",$elem,"",$self->{VALUE})) { $self->{VAL} = $self->calcStr($elem); push(@valid_elems,$elem); diff -ur nil-is-defined/t/xpath.t queries-are-broken-too/t/xpath.t --- nil-is-defined/t/xpath.t 2012-01-04 16:11:30.000000000 +0200 +++ queries-are-broken-too/t/xpath.t 2012-01-04 23:27:08.000000000 +0200 @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests=>113; +use Test::More tests=>121; BEGIN{ use_ok("XML::Stream","Node","Tree"); } @@ -113,6 +113,14 @@ is( $#value, 0, "'helo' - Only one matches?"); is( &XML::Stream::GetXMLData("value",$value[0],'','helo_exit'), "0", "correct value?"); + @value = &XML::Stream::XPath($node, 'helo/@helo_exit'); + is( $#value, 0, "'helo/\@helo_exit' - Only one matches?"); + is( $value[0], 0, "correct value?"); + + @value = &XML::Stream::XPath($node, 'helo[@helo_exit="0"]'); + is( $#value, 0, "'helo[\@helo_exit=\"0\"]' - Only one matches?"); + is( &XML::Stream::GetXMLData("value",$value[0],'','helo_exit'), "0", "correct value?"); + @value = &XML::Stream::XPath($node, 'size'); is( $#value, 0, "'size' - Only one matches?"); is( &XML::Stream::GetXMLData("value",$value[0],'','size_exit'), "", "correct value?");
Subject: nil-is-defined.diff
diff -ur backup/lib/XML/Stream/Node.pm nil-is-defined/lib/XML/Stream/Node.pm --- backup/lib/XML/Stream/Node.pm 2011-07-19 19:49:32.000000000 +0300 +++ nil-is-defined/lib/XML/Stream/Node.pm 2012-01-04 00:38:56.000000000 +0200 @@ -794,7 +794,7 @@ return $str; } return $XMLTree->get_attrib($attrib) - if $XMLTree->get_attrib($attrib); + if defined $XMLTree->get_attrib($attrib); } #--------------------------------------------------------------------- # Return a pointer to a new XML::Parser::Tree object that has the diff -ur backup/t/buildxml.t nil-is-defined/t/buildxml.t --- backup/t/buildxml.t 2011-07-19 19:49:32.000000000 +0300 +++ nil-is-defined/t/buildxml.t 2012-01-04 00:06:01.000000000 +0200 @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 56; +use Test::More tests => 62; BEGIN{ use_ok( "XML::Stream","Tree", "Node" ); } @@ -68,6 +68,8 @@ <bing test='2'/> <bingo/></startest>"; $packets[16] = "<cdata_test test='6'>This is cdata with &lt;tags/&gt; embedded &lt;in&gt;it&lt;/in&gt;.<bingo/></cdata_test>"; +$packets[17] = "<helo helo_exit='0'><bingo/></helo>"; +$packets[18] = "<size size_exit=''><bingo/></size>"; my $packetIndex; foreach my $xmlType ("tree","node") diff -ur backup/t/parse_node.t nil-is-defined/t/parse_node.t --- backup/t/parse_node.t 2011-07-19 19:49:32.000000000 +0300 +++ nil-is-defined/t/parse_node.t 2012-01-03 23:51:25.000000000 +0200 @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 6; +use Test::More tests => 8; use XML::Stream qw( Node ); my @tests; @@ -17,7 +17,7 @@ last if ($status{$sid} == -1); } -foreach (2..6) { +foreach (2..8) { ok $tests[$_]; } @@ -25,6 +25,20 @@ my $sid = shift; my ($packet) = @_; + if ($packet->get_tag eq "helo" && $packet->get_attrib("helo_exit") == 0) { + $tests[7] = 1; + } + + if ($packet->get_tag eq "size" && $packet->get_attrib("size_exit") eq '') { + $tests[8] = 1; + } + + if ($packet->get_tag eq "foo") { + if ($packet->get_attrib("test") eq '') { + $tests[1] = 1; + } + } + return unless $packet->get_attrib("test"); if ($packet->get_attrib("test") eq "2") { diff -ur backup/t/test.xml nil-is-defined/t/test.xml --- backup/t/test.xml 2011-07-19 19:49:32.000000000 +0300 +++ nil-is-defined/t/test.xml 2012-01-04 00:03:40.000000000 +0200 @@ -64,4 +64,6 @@ <bing test='2'/> </startest> <cdata_test test='6'><![CDATA[This is cdata with <tags/> embedded <in>it</in>.]]></cdata_test> + <helo helo_exit='0'/> + <size size_exit=''/> </test_xml> diff -ur backup/t/xpath.t nil-is-defined/t/xpath.t --- backup/t/xpath.t 2011-07-19 19:49:32.000000000 +0300 +++ nil-is-defined/t/xpath.t 2012-01-04 16:11:30.000000000 +0200 @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests=>105; +use Test::More tests=>113; BEGIN{ use_ok("XML::Stream","Node","Tree"); } @@ -109,5 +109,12 @@ is( &XML::Stream::GetXMLData("value",$value[0]), "foo1", "correct value?"); is( &XML::Stream::GetXMLData("value",$value[1]), "foo2", "correct value?"); + @value = &XML::Stream::XPath($node, 'helo'); + is( $#value, 0, "'helo' - Only one matches?"); + is( &XML::Stream::GetXMLData("value",$value[0],'','helo_exit'), "0", "correct value?"); + + @value = &XML::Stream::XPath($node, 'size'); + is( $#value, 0, "'size' - Only one matches?"); + is( &XML::Stream::GetXMLData("value",$value[0],'','size_exit'), "", "correct value?"); }