Hi,
I'm trying to run XML::LibXML 1.63 on a Debian system with libxml2
2.6.29. Unfortunately I get two failing tests in t/03doc.t:
t/03doc.......................# Test 78 got: "" (t/03doc.t at line 209)
# Expected: <UNDEF>
# t/03doc.t line 209 is: ok( $pi->textContent, undef);
# Test 79 got: "" (t/03doc.t at line 210)
# Expected: <UNDEF>
# t/03doc.t line 210 is: ok( $pi->getData, undef);
t/03doc.......................FAILED tests 78-79
The failing code creates a processing instruction node and checks if the
textContent is undef initially. Unfortunately it isn't as the call to
->textContent() basically boils down to xmlXPathCastNodeToString(),
which will, if the nodes content is NULL currently, return a newly
allocated empty string.
See xpath.c from the libxml2 2.6.29 distribution:
xmlChar *
xmlXPathCastNodeToString (xmlNodePtr node) {
xmlChar *ret;
if ((ret = xmlNodeGetContent(node)) == NULL)
ret = xmlStrdup((const xmlChar *) "");
return(ret);
}
Although I couldn't find anything in the changelogs I checked out some
libxml2 releases and found out that this behavior has been introduced
with version 2.6.29.
Previous versions of libxml2 defined this function like that:
xmlChar *
xmlXPathCastNodeToString (xmlNodePtr node) {
return(xmlNodeGetContent(node));
}
That way you'd get NULL back C2Sv would convert that to &PL_sv_undef.
I'm not too sure what the right fix would be. Make the tests check for
either "" or undef based on the version of libxml2 they're linked
against? Have the string_value function handle NULL specially (replace
it by an empty string) to make the new behavior of 2.6.29 available for
older versions of libxml2 as well?
What do you think?
TIA,
Flo