Subject: | [patch] $node->normalize stops processing when an empty element node is encountered |
when calling normalize on a node, processing of children nodes will stop
when an empty element node is encountered.
Attached is a script demonstrating this behavior and a patch with an
updated normalize test and a fix for the issue. domNodeNormalizeList
shouldn't return an error when given an empty node list to process.
Subject: | normalizeTest.pl |
#!/usr/bin/perl
use XML::LibXML;
my $doc = XML::LibXML::Document->new();
my $e1 = $doc->createElement('foo');
$e1->addNewChild(undef, 'bar');
$e1->appendChild($doc->createTextNode('bar')) for(1..3);
print "Child Nodes before normalize: " . $e1->childNodes->size . "\n";
$e1->normalize;
print "Child Nodes after normalize: " . $e1->childNodes->size . "\n";
Subject: | libxml-03.patch |
diff --git a/dom.c b/dom.c
index 546108c..686418a 100644
--- a/dom.c
+++ b/dom.c
@@ -1227,9 +1227,6 @@ domNodeNormalize( xmlNodePtr node );
int
domNodeNormalizeList( xmlNodePtr nodelist )
{
- if ( nodelist == NULL )
- return(0);
-
while ( nodelist ){
if ( domNodeNormalize( nodelist ) == 0 )
return(0);
diff --git a/t/06elements.t b/t/06elements.t
index f6c08a2..13eab05 100644
--- a/t/06elements.t
+++ b/t/06elements.t
@@ -218,6 +218,8 @@ print "# 4. Text Append and Normalization\n";
my $t2 = $doc->createTextNode( "bar2" );
my $t3 = $doc->createTextNode( "bar3" );
my $e = $doc->createElement("foo");
+ my $e2 = $doc->createElement("bar");
+ $e->appendChild( $e2 );
$e->appendChild( $t1 );
$e->appendChild( $t2 );
$e->appendChild( $t3 );
@@ -226,12 +228,12 @@ print "# 4. Text Append and Normalization\n";
# this is the correct behaviour for DOM. the nodes are still
# refered
- ok( scalar( @cn ), 3 );
+ ok( scalar( @cn ), 4 );
$e->normalize;
@cn = $e->childNodes;
- ok( scalar( @cn ), 1 );
+ ok( scalar( @cn ), 2 );
ok(not defined $t2->parentNode);
ok(not defined $t3->parentNode);