Commits

Shlomi Fish committed 8701eac

Fix "IDs of elements is lost when importing nodes" (RT #69520).

Comments (0)

Files changed (4)

     rebuild the C-files.
     - Add no warnings 'recursion' to lib/XML/LibXML/Error.pm to get rid of
     a "Deep recursion" warning.
+    - Fix "IDs of elements is lost when importing nodes"
+        - https://rt.cpan.org/Public/Bug/Display.html?id=69520
+        - With t/48importing_nodes_IDs_rt_69520.t .
 
 1.80            Tue Jul 12 23:35:03 IDT 2011
     - Fix https://rt.cpan.org/Public/Bug/Display.html?id=69082 :
 docs/libxml.dbk
 dom.c
 dom.h
+example/JBR-ALLENtrees.htm
 example/article.xml
 example/article_bad.xml
 example/article_external_bad.xml
 example/article_internal_bad.xml
 example/bad.dtd
 example/bad.xml
-example/thedieline.rss
 example/catalog.xml
 example/cb_example.pl
 example/complex/complex.dtd
 example/enc2_latin2.html
 example/enc_latin2.html
 example/ext_ent.dtd
-example/JBR-ALLENtrees.htm
 example/ns.xml
 example/test.dtd
 example/test.html
 example/test2.xml
 example/test3.xml
 example/test4.xml
+example/thedieline.rss
 example/utf-16-1.html
 example/utf-16-2.html
 example/utf-16-2.xml
 perl-libxml-sax.c
 perl-libxml-sax.h
 ppport.h
+scripts/Test.pm-to-Test-More.pl
 scripts/fast-eumm.pl
-scripts/Test.pm-to-Test-More.pl
 scripts/prints-to-comments.pl
 t/01basic.t
 t/02parse.t
 t/16docnodes.t
 t/17callbacks.t
 t/18docfree.t
+t/19die_on_invalid_utf8_rt_58848.t
 t/19encoding.t
-t/19die_on_invalid_utf8_rt_58848.t
 t/20extras.t
 t/21catalog.t
 t/23rawfunctions.t
 t/46err_column.t
 t/47load_xml_callbacks.t
 t/48_rt55000.t
+t/48importing_nodes_IDs_rt_69520.t
 t/49_load_html.t
 t/49global_extent.t
+t/60error_prev_chain.t
 t/60struct_error.t
-t/60error_prev_chain.t
 t/61error.t
 t/80registryleak.t
 t/90threads.t
             return_node = (xmlNodePtr) xmlCopyDtd((xmlDtdPtr) node);
         }
         else {
-            return_node = xmlCopyNode( node, 1 );
+            return_node = xmlDocCopyNode( node, doc, 1 );
         }
     }
 

t/48importing_nodes_IDs_rt_69520.t

+# This is a test for:
+# https://rt.cpan.org/Public/Bug/Display.html?id=69520
+
+=head1 DESCRIPTION
+
+IDs of elements is lost when importing nodes from another document.
+When call method 'importNode' executed function 'xmlNodeCopy' from the
+library libxml2, which does not import IDs.
+Propose to replace the call "xmlNodeCopy" on "xmlDocNodeCopy" in the file
+"dom.c".
+
+=head1 THANKS.
+
+Yuriy Ustushenko .
+
+=cut
+
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+
+use XML::LibXML;
+
+{
+    my $doc = XML::LibXML->load_xml(string => <<'EOT');
+<root>
+    <item xml:id="id1">item1</item>
+</root>
+EOT
+
+    my $elem = $doc->getElementById('id1');
+    # TEST
+    ok ($elem, 'Orig doc has id1');
+
+    # TEST
+    is ($elem->textContent(), 'item1', 'Content of orig doc elem id1');
+
+    my $doc2 = XML::LibXML->createDocument( "1.0", "UTF-8" );
+    $doc2->setDocumentElement( $doc2->importNode( $doc->documentElement() ) );
+
+    my $elem2 = $doc2->getElementById('id1');
+    # TEST
+    ok ($elem2, 'Doc2 after importNode has id1');
+
+    # TEST
+    is ($elem2->textContent(), 'item1', 'Doc2 after importNode has id1');
+}
+
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2011 by Shlomi Fish
+
+This program is distributed under the MIT (X11) License:
+L<http://www.opensource.org/licenses/mit-license.php>
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+=cut