Commits

Anonymous committed 83fc667

fix #46238 - & passed to createAttribute and createAttributeNS

Comments (0)

Files changed (2)

         xmlChar * name = NULL;
         xmlChar * value = NULL;
         xmlAttrPtr newAttr = NULL;
+        xmlChar * buffer = NULL;
     CODE:
         name = nodeSv2C( pname , (xmlNodePtr) self );
         if ( !LibXML_test_node_name( name ) ) {
         }
 
         value = nodeSv2C( pvalue , (xmlNodePtr) self );
-        newAttr = xmlNewDocProp( self, name, value );
+        /* unlike xmlSetProp, xmlNewDocProp does not encode entities in value */
+        buffer = xmlEncodeEntitiesReentrant(self, value);
+        newAttr = xmlNewDocProp( self, name, buffer );
         RETVAL = PmmNodeToSv((xmlNodePtr)newAttr, PmmPROXYNODE(self));
 
         xmlFree(name);
+        xmlFree(buffer);
         if ( value ) {
             xmlFree(value);
         }
             }
         }
         else {
-            newAttr = xmlNewDocProp( self, name, value );
+            xmlChar *buffer;
+            /* unlike xmlSetProp, xmlNewDocProp does not encode entities in value */
+            buffer = xmlEncodeEntitiesReentrant(self, value);
+            newAttr = xmlNewDocProp( self, name, buffer );
             RETVAL = PmmNodeToSv((xmlNodePtr)newAttr,PmmPROXYNODE(self));
             xmlFree(name);
+            xmlFree(buffer);
             if ( value ) {
                 xmlFree(value);
             }
 use Test;
 use strict;
 
-BEGIN { plan tests => 166 };
+BEGIN { plan tests => 168 };
 use XML::LibXML;
 use XML::LibXML::Common qw(:libxml);
 
         }
 
     }
-
-
+    {
+      my $elem = $doc->createElement('foo');
+      my $attr = $doc->createAttribute(attr => 'e & f');
+      $elem->addChild($attr);
+      ok ($elem->toString() eq '<foo attr="e &amp; f"/>');
+      $elem->removeAttribute('attr');
+      $attr = $doc->createAttributeNS(undef,'attr2' => 'a & b');
+      $elem->addChild($attr);
+      print $elem->toString(),"\n";
+      ok ($elem->toString() eq '<foo attr2="a &amp; b"/>');
+    }
     {
         eval {
             my $attr = $doc->createAttributeNS("http://kungfoo", "kung:foo","bar");