Re: Bundling libxml2 default?
| From: | Moriyoshi Koizumi | Date: | Fri, 16 May 2003 23:03:06 +0000 |
| Subject: | Re: Bundling libxml2 default? | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-1623@lists.php.net to get a copy of this message | ||
Adam Dickmeiss <adam@indexdata.dk> wrote:
> On Sat, May 17, 2003 at 06:11:02AM +0900, Moriyoshi Koizumi wrote:
> > Could you try the attached patch and see if it works?
> I did a similar thing, but it didn't made a difference. To
> be 100% sure I applied your patch and tried again. No luck:(
>
> The info for xmlCreatePushParserCtxt indicates that 4 leading
> bytes are needed to detect decoding.
>
> http://xmlsoft.org/html/libxml-parser.html#xmlCreatePushParserCtxt
Thanks for testing. After some investigation, I found the patch was
actually bogus. Sorry! As far as I looked into the sources, it seems the
libxml implementation does the encoding detection again after the parser
creation if ctxt->charset = XML_CHAR_ENCODING_NONE.
The right one is attached, and the test script follows as well:
Moriyoshi
<?php
$xml = '<?xml version="1.0" encoding="UTF-16"
?><test></test>';
function foo($parser, $elem, $dummy) {
var_dump($elem);
}
$xml = iconv("UTF-8", "UTF-16", $xml);
$parser = xml_parser_create('');
xml_set_element_handler($parser, 'foo', 'foo');
xml_parse($parser, $xml, TRUE);
?>
Index: ext/xml/compat.c =================================================================== RCS file: /repository/php4/ext/xml/compat.c,v retrieving revision 1.6 diff -u -r1.6 compat.c --- ext/xml/compat.c 7 May 2003 20:53:23 -0000 1.6 +++ ext/xml/compat.c 16 May 2003 22:57:03 -0000 @@ -276,7 +276,11 @@ parser->mem_hdlrs.free_fcn(parser->parser); return NULL; } - parser->parser->encoding = xmlStrdup(encoding); + if (encoding != NULL) { + parser->parser->encoding = xmlStrdup(encoding); + } else { + parser->parser->charset = XML_CHAR_ENCODING_NONE; + } if (sep != NULL) { parser->namespace = 1; parser->_ns_map = xmlHashCreate(10);
Index: ext/xml/compat.c =================================================================== RCS file: /repository/php4/ext/xml/compat.c,v retrieving revision 1.6 diff -u -r1.6 compat.c --- ext/xml/compat.c 7 May 2003 20:53:23 -0000 1.6 +++ ext/xml/compat.c 16 May 2003 22:57:03 -0000 @@ -276,7 +276,11 @@ parser->mem_hdlrs.free_fcn(parser->parser); return NULL; } - parser->parser->encoding = xmlStrdup(encoding); + if (encoding != NULL) { + parser->parser->encoding = xmlStrdup(encoding); + } else { + parser->parser->charset = XML_CHAR_ENCODING_NONE; + } if (sep != NULL) { parser->namespace = 1; parser->_ns_map = xmlHashCreate(10);