Re: Re: xml_parser_create patch

From: Date: Fri, 09 May 2003 14:11:06 +0000
Subject: Re: Re: xml_parser_create patch
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-1408@lists.php.net to get a copy of this message
Hi, here is another patch that recognizes "" as "proper XML decoding". I also discovered incorrect string comparison of other encodings in the xml_parser_create handler .. Basically, a call such as xml_parser_create("UT"); would be treated as xml_parser_create("UTF-8"); .. which can't be right. It should trigger an error. The patch only includes xml_parser_create not _ns variant. You people with karma can figure that out. I have a character encoding handler for Expat that allows expat to use conversion for all encodings it doesn't know. I used it in another piece of software but it could be easily modified for ext/xml. Now, since Expat is fading away that might not be of interest. -- Adam On Thu, May 08, 2003 at 09:19:08PM +0900, Moriyoshi Koizumi wrote: > Derick Rethans <derick@php.net> wrote: > > > On Wed, 7 May 2003, Adam Dickmeiss wrote: > > > > > On Wed, May 07, 2003 at 12:33:20PM +0200, nicos@php.net wrote: > > > > -1 for the patch if it doesn't have a default value for the encoding. > > > > > > > > We don't want to break BC again. > > > I respect that. I hope Streling does too with a new layer on > > > top .. > > > > > > How about letting the empty string mean : Auto encoding?? > > > > > > xml_parser_create(""); // any decoding! (pass 0 to Expat) > > > > too much magic. > > I don't think so, as such a convension already exists in the > third parameter of htmlentities(). Are you going to come up with any other > solution? > > Moriyoshi > > > Derick > > > > -- > > "my other box is your windows PC" > > ------------------------------------------------------------------------- > > Derick Rethans > > http://derickrethans.nl/ > > PHP Magazine - PHP Magazine for Professionals > > http://php-mag.net/ > > ------------------------------------------------------------------------- > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Adam Dickmeiss mailto:adam@indexdata.dk http://www.indexdata.dk Index Data T: +45 33410100 Mob.: 212 212 66

=================================================================== RCS file: /repository/php4/ext/xml/xml.c,v retrieving revision 1.123 diff -u -r1.123 xml.c --- xml.c 8 May 2003 16:01:50 -0000 1.123 +++ xml.c 9 May 2003 13:58:19 -0000 @@ -1026,6 +1026,7 @@ { xml_parser *parser; int argc; + int auto_decoding = 0; zval **encodingArg; XML_Char *encoding; @@ -1040,25 +1041,27 @@ /* The supported encoding types are hardcoded here because * we are limited to the encodings supported by expat/xmltok. */ - if (strncasecmp(Z_STRVAL_PP(encodingArg), "ISO-8859-1", - Z_STRLEN_PP(encodingArg)) == 0) { + if (strcasecmp(Z_STRVAL_PP(encodingArg), "") == 0) { + encoding = XML(default_encoding); + auto_decoding = 1; + } else if (strcasecmp(Z_STRVAL_PP(encodingArg), "ISO-8859-1") == 0) { encoding = "ISO-8859-1"; - } else if (strncasecmp(Z_STRVAL_PP(encodingArg), "UTF-8", - Z_STRLEN_PP(encodingArg)) == 0) { - encoding = "UTF-8"; - } else if (strncasecmp(Z_STRVAL_PP(encodingArg), "US-ASCII", - Z_STRLEN_PP(encodingArg)) == 0) { + } else if (strcasecmp(Z_STRVAL_PP(encodingArg), "UTF-8") == 0) { + encoding = "UTF-8"; + } else if (strcasecmp(Z_STRVAL_PP(encodingArg), "US-ASCII") == 0) { encoding = "US-ASCII"; } else { /* UTF-16 not supported */ php_error_docref(NULL TSRMLS_CC, E_WARNING, "unsupported source encoding \"%s\"", Z_STRVAL_PP(encodingArg)); RETURN_FALSE; } - } else { - encoding = XML(default_encoding); - } - + } else { + encoding = XML(default_encoding); + } + parser = ecalloc(sizeof(xml_parser), 1); - parser->parser = XML_ParserCreate_MM(encoding, &php_xml_mem_hdlrs, NULL); + parser->parser = XML_ParserCreate_MM(auto_decoding ? 0 : encoding, + &php_xml_mem_hdlrs, NULL); + parser->target_encoding = encoding; parser->case_folding = 1; parser->object = NULL;
« previous php.internals (#1408) next »