1. Shlomi Fish
  2. perl-XML-LibXML

Commits

Shlomi Fish  committed b2f31d5

Correct RT #55000.

If an element contains both a default namespace declaration and a second
namespace declaration, adding an attribute using the default namespace
declaration will cause that attribute to have the other prefix.

  • Participants
  • Parent commits 5914610
  • Branches default

Comments (0)

Files changed (4)

File Changes

View file
  • Ignore whitespace
         - Apply a somewhat modified patch from:
             - https://rt.cpan.org/Ticket/Display.html?id=52368
     - Add t/pod.t .
+    - Fix https://rt.cpan.org/Ticket/Display.html?id=55000 :
+        - Apply modified patch in the bug report.
+        - << If an element contains both a default namespace declaration and a 
+        second namespace declaration, adding an attribute using the default 
+        namespace declaration will cause that attribute to have the other 
+        prefix. >>
 
 1.74            Thu Jun 23 16:20:42 IDT 2011
     - More work on the t/*.t test scripts.

File LibXML.xs

View file
  • Ignore whitespace
                  }
             }
             else if ( !ns->prefix ) {
-                if ( ns->next && ns->next->prefix ) {
+                if ( prefix && xmlStrlen( prefix ) ) {
+                    ns = xmlSearchNs(self->doc, self, prefix);
+
+                    if ( ns ) {
+                        if ( !xmlStrEqual(ns->href, nsURI) ) {
+                            ns = NULL;
+                        }
+                    }
+                    else {
+                        ns = xmlNewNs(self, nsURI , prefix );
+                    }
+                }
+                else if ( ns->next && ns->next->prefix ) {
                     ns = ns->next;
                 }
-                else if ( prefix && xmlStrlen( prefix ) ) {
-                    ns = xmlNewNs(self, nsURI , prefix );
-                }
                 else {
                     ns = NULL;
                 }

File MANIFEST

View file
  • Ignore whitespace
 t/45regex.t
 t/46err_column.t
 t/47load_xml_callbacks.t
+t/48_rt55000.t
 t/60struct_error.t
 t/61error.t
 t/80registryleak.t

File t/48_rt55000.t

View file
  • Ignore whitespace
+
+use strict;
+use warnings;
+
+=head1 DESCRIPTION
+If an element contains both a default namespace declaration and a second
+namespace declaration, adding an attribute using the default namespace
+declaration will cause that attribute to have the other prefix.
+
+OS Version: FreeBSD 6.3-RELEASE
+Perl Version: v5.8.8
+LibXML Version: 1.70
+
+See L<https://rt.cpan.org/Ticket/Display.html?id=55000> .
+
+=cut
+
+use Test::More tests => 2;
+
+use XML::LibXML;
+
+my $xml_string = <<'XML';
+<?xml version="1.0" encoding="UTF-8"?>
+<element xmlns="uri"
+xmlns:wrong="other">
+</element>
+XML
+
+my $parser = XML::LibXML->new;
+my $doc = $parser->parse_string($xml_string);
+my $root = $doc->documentElement();
+$root->setAttributeNS("uri", "prefix:attribute", "text");
+
+my $string = $doc->toString(1);
+
+# TEST
+unlike ($string, qr/\bwrong:attribute="text"/, 
+    "Not placed in the wrong namespace");
+
+# TEST
+like ($string, qr/\b(?:prefix:)?attribute="text"/, 
+    "Placed in the right namespace");
+