Commits

ph...@9ae0c189-cd1f-4510-a509-f4891f5cf20d  committed 4b22bbc

Modified Files:
perl-libxml-mm.c
[fix] make use of libxml's internal charset flag rather than relying on
the encoding flag of the proxy node (which is obsolete by now)
(fixes problem reported by Andrew Alakozow)

  • Participants
  • Parent commits e4ed13c

Comments (0)

Files changed (1)

File perl-libxml-mm.c

 
 #define PmmENCODING(node)    node->encoding
 #define PmmNodeEncoding(node) ((ProxyNodePtr)(node->_private))->encoding
-
+#define PmmDocEncoding(node) (node->charset)
 /* creates a new proxy node from a given node. this function is aware
  * about the fact that a node may already has a proxy structure.
  */
     ProxyNodePtr proxy = NULL;
 
     if ( node == NULL ) {
-        warn( "no node found\n" );
+        xs_warn( "no node found\n" );
         return NULL;
     }
 
             /* warn( "encoded string is %s" , retval); */
         }
         else {
-            xs_warn( "b0rked encoiding!\n");
+            /* warn( "b0rked encoiding!\n"); */
         }
         
         xmlBufferFree( in );
 
     if ( refnode != NULL ) {
         xmlDocPtr real_doc = refnode->doc;
-        if ( real_doc && real_doc->encoding != NULL ) {
+        if ( real_doc != NULL && real_doc->encoding != NULL ) {
 
-            xmlChar * decoded = PmmFastDecodeString( PmmNodeEncoding(real_doc) ,
+            xmlChar * decoded = PmmFastDecodeString( PmmDocEncoding(real_doc) ,
                                                      (const xmlChar *)string,
                                                      (const xmlChar*)real_doc->encoding);
             len = xmlStrlen( decoded );
        perl. in this cases the library assumes, all strings are in
        UTF8. if a programmer likes to have the intelligent code, he
        needs to upgrade perl */
-#ifdef HAVE_UTF8        
+
     if ( refnode != NULL ) {
         xmlDocPtr real_dom = refnode->doc;
         xs_warn("have node!");
                     xs_warn( "no undefs" );
 #ifdef HAVE_UTF8
                     xs_warn( "use UTF8" );
-                    if( !DO_UTF8(scalar) && real_dom->encoding != NULL ) {
+                    if( !DO_UTF8(scalar) && real_dom != NULL && real_dom->encoding != NULL ) {
                         xs_warn( "string is not UTF8\n" );
 #else
-                    if ( real_dom->encoding != NULL ) {        
+                    if ( real_dom != NULL && real_dom->encoding != NULL ) {        
 #endif
                         xs_warn( "domEncodeString!" );
-                        ts= PmmFastEncodeString( PmmNodeEncoding(real_dom),
+                      /*  if ( string == NULL || *string == 0 ) warn("string is empty" ); */
+                       
+                        ts= PmmFastEncodeString( PmmDocEncoding(real_dom),
                                                  string,
                                                  (const xmlChar*)real_dom->encoding );
+
                         xs_warn( "done!" );
                         if ( string != NULL ) {
                             xmlFree(string);
                         xs_warn( "no encoding set, use UTF8!\n" );
                     }
                 }
-                if ( string == NULL ) xs_warn( "string is NULL\n" );
+                /* if ( string == NULL ) warn( "string is NULL\n" ); */
                 return string;
             }
             else {
         }
     }
     xs_warn("no encoding !!");
-#endif
 
     return  Sv2C( scalar, NULL ); 
 }