]> granicus.if.org Git - php/commitdiff
fix bug #50661 (DOMDocument::loadXML does not allow UTF-16)
authorRob Richards <rrichards@php.net>
Wed, 6 Jan 2010 13:13:17 +0000 (13:13 +0000)
committerRob Richards <rrichards@php.net>
Wed, 6 Jan 2010 13:13:17 +0000 (13:13 +0000)
add test

NEWS
ext/dom/document.c
ext/dom/tests/bug50661.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index bb401046bf5e613801432fc393e4b63a2d019b14..8566496367c1b9a52bf09614f09e5ac3eb855893 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ PHP                                                                        NEWS
   (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).
index 8dac8cfa1bd4a60108b62a84b29b67af60ea162b..8b212ed03ec8ada38eec80e67a4b6ae2229faff6 100644 (file)
@@ -1542,7 +1542,7 @@ char *_dom_get_valid_file_path(char *source, char *resolved_path, int resolved_p
 }
 /* }}} */
 
-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 @@ static xmlDocPtr dom_document_parser(zval *id, int mode, char *source, int optio
                }
                
        } else {
-               ctxt = xmlCreateDocParserCtxt(source);
+               ctxt = xmlCreateMemoryParserCtxt(source, source_len);
        }
 
        if (ctxt == NULL) {
@@ -1682,7 +1682,7 @@ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) {
                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;
diff --git a/ext/dom/tests/bug50661.phpt b/ext/dom/tests/bug50661.phpt
new file mode 100644 (file)
index 0000000..3760db9
--- /dev/null
@@ -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/>