rrichards                                Wed, 06 Jan 2010 13:13:17 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=293176

Log:
fix bug #50661 (DOMDocument::loadXML does not allow UTF-16)
add test

Bug: http://bugs.php.net/50661 (Assigned) DOMDocument::loadXML does not allow 
UTF-16
      
Changed paths:
    U   php/php-src/branches/PHP_5_2/NEWS
    U   php/php-src/branches/PHP_5_2/ext/dom/document.c
    A   php/php-src/branches/PHP_5_2/ext/dom/tests/bug50661.phpt
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/dom/document.c
    A   php/php-src/branches/PHP_5_3/ext/dom/tests/bug50661.phpt
    U   php/php-src/trunk/ext/dom/document.c
    A   php/php-src/trunk/ext/dom/tests/bug50661.phpt

Modified: php/php-src/branches/PHP_5_2/NEWS
===================================================================
--- php/php-src/branches/PHP_5_2/NEWS   2010-01-06 12:54:53 UTC (rev 293175)
+++ php/php-src/branches/PHP_5_2/NEWS   2010-01-06 13:13:17 UTC (rev 293176)
@@ -11,6 +11,7 @@

 - Fixed build of mysqli with MySQL 5.5.0-m2. (Andrey)

+- Fixed bug #50661 (DOMDocument::loadXML does not allow UTF-16). (Rob)
 - Fixed bug #50657 (copy() with an empty (zero-byte) HTTP source succeeds but
   returns false). (Ilia)
 - Fixed bug #50636 (MySQLi_Result sets values before calling constructor).

Modified: php/php-src/branches/PHP_5_2/ext/dom/document.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/dom/document.c     2010-01-06 12:54:53 UTC 
(rev 293175)
+++ php/php-src/branches/PHP_5_2/ext/dom/document.c     2010-01-06 13:13:17 UTC 
(rev 293176)
@@ -1598,7 +1598,7 @@


 /* {{{ */
-static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, int 
options TSRMLS_DC) {
+static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, int 
source_len, int options TSRMLS_DC) {
     xmlDocPtr ret;
     xmlParserCtxtPtr ctxt = NULL;
        dom_doc_propsptr doc_props;
@@ -1634,7 +1634,7 @@
                }

        } else {
-               ctxt = xmlCreateDocParserCtxt(source);
+               ctxt = xmlCreateMemoryParserCtxt(source, source_len);
        }

        if (ctxt == NULL) {
@@ -1737,7 +1737,7 @@
                RETURN_FALSE;
        }

-       newdoc = dom_document_parser(id, mode, source, options TSRMLS_CC);
+       newdoc = dom_document_parser(id, mode, source, source_len, options 
TSRMLS_CC);

        if (!newdoc)
                RETURN_FALSE;

Added: php/php-src/branches/PHP_5_2/ext/dom/tests/bug50661.phpt
===================================================================
--- php/php-src/branches/PHP_5_2/ext/dom/tests/bug50661.phpt                    
        (rev 0)
+++ php/php-src/branches/PHP_5_2/ext/dom/tests/bug50661.phpt    2010-01-06 
13:13:17 UTC (rev 293176)
@@ -0,0 +1,16 @@
+--TEST--
+Bug #50661 (DOMDocument::loadXML does not allow UTF-16).
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+$data = "\xFE\xFF\x00\x3C\x00\x66\x00\x6F\x00\x6F\x00\x2F\x00\x3E";
+
+$dom = new DOMDocument();
+$dom->loadXML($data);
+echo $dom->saveXML();
+
+?>
+--EXPECT--
+<?xml version="1.0"?>
+<foo/>

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2010-01-06 12:54:53 UTC (rev 293175)
+++ php/php-src/branches/PHP_5_3/NEWS   2010-01-06 13:13:17 UTC (rev 293176)
@@ -8,6 +8,7 @@
   (Ilia)
 - Added stream_resolve_include_path(). (Mikko)

+- Fixed bug #50661 (DOMDocument::loadXML does not allow UTF-16). (Rob)
 - Fixed bug #50657 (copy() with an empty (zero-byte) HTTP source succeeds
   but returns false). (Ilia)
 - Fixed bug #50636 (MySQLi_Result sets values before calling constructor).

Modified: php/php-src/branches/PHP_5_3/ext/dom/document.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/dom/document.c     2010-01-06 12:54:53 UTC 
(rev 293175)
+++ php/php-src/branches/PHP_5_3/ext/dom/document.c     2010-01-06 13:13:17 UTC 
(rev 293176)
@@ -1542,7 +1542,7 @@
 }
 /* }}} */

-static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, int 
options TSRMLS_DC) /* {{{ */
+static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, int 
source_len, int options TSRMLS_DC) /* {{{ */
 {
     xmlDocPtr ret;
     xmlParserCtxtPtr ctxt = NULL;
@@ -1579,7 +1579,7 @@
                }

        } else {
-               ctxt = xmlCreateDocParserCtxt(source);
+               ctxt = xmlCreateMemoryParserCtxt(source, source_len);
        }

        if (ctxt == NULL) {
@@ -1682,7 +1682,7 @@
                RETURN_FALSE;
        }

-       newdoc = dom_document_parser(id, mode, source, options TSRMLS_CC);
+       newdoc = dom_document_parser(id, mode, source, source_len, options 
TSRMLS_CC);

        if (!newdoc)
                RETURN_FALSE;

Added: php/php-src/branches/PHP_5_3/ext/dom/tests/bug50661.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/dom/tests/bug50661.phpt                    
        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/dom/tests/bug50661.phpt    2010-01-06 
13:13:17 UTC (rev 293176)
@@ -0,0 +1,16 @@
+--TEST--
+Bug #50661 (DOMDocument::loadXML does not allow UTF-16).
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+$data = "\xFE\xFF\x00\x3C\x00\x66\x00\x6F\x00\x6F\x00\x2F\x00\x3E";
+
+$dom = new DOMDocument();
+$dom->loadXML($data);
+echo $dom->saveXML();
+
+?>
+--EXPECT--
+<?xml version="1.0"?>
+<foo/>

Modified: php/php-src/trunk/ext/dom/document.c
===================================================================
--- php/php-src/trunk/ext/dom/document.c        2010-01-06 12:54:53 UTC (rev 
293175)
+++ php/php-src/trunk/ext/dom/document.c        2010-01-06 13:13:17 UTC (rev 
293176)
@@ -1544,7 +1544,7 @@
 }
 /* }}} */

-static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, int 
options TSRMLS_DC) /* {{{ */
+static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, int 
source_len, int options TSRMLS_DC) /* {{{ */
 {
     xmlDocPtr ret;
     xmlParserCtxtPtr ctxt = NULL;
@@ -1581,7 +1581,7 @@
                }

        } else {
-               ctxt = xmlCreateDocParserCtxt(source);
+               ctxt = xmlCreateMemoryParserCtxt(source, source_len);
        }

        if (ctxt == NULL) {
@@ -1695,7 +1695,7 @@
                }
        }

-       newdoc = dom_document_parser(id, mode, source.s, options TSRMLS_CC);
+       newdoc = dom_document_parser(id, mode, source.s, source_len, options 
TSRMLS_CC);

        if (source_type == IS_UNICODE) {
                efree(source.s);

Added: php/php-src/trunk/ext/dom/tests/bug50661.phpt
===================================================================
--- php/php-src/trunk/ext/dom/tests/bug50661.phpt                               
(rev 0)
+++ php/php-src/trunk/ext/dom/tests/bug50661.phpt       2010-01-06 13:13:17 UTC 
(rev 293176)
@@ -0,0 +1,16 @@
+--TEST--
+Bug #50661 (DOMDocument::loadXML does not allow UTF-16).
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+$data = b"\xFE\xFF\x00\x3C\x00\x66\x00\x6F\x00\x6F\x00\x2F\x00\x3E";
+
+$dom = new DOMDocument();
+$dom->loadXML($data);
+echo $dom->saveXML();
+
+?>
+--EXPECT--
+<?xml version="1.0"?>
+<foo/>

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to