]> 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

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

index 2a04666afc6486298dca10728f8adade28661902..7362e3b8028dfcbffe370d243284924aff01b33e 100644 (file)
@@ -1544,7 +1544,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;
@@ -1581,7 +1581,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) {
@@ -1695,7 +1695,7 @@ static void dom_parse_document(INTERNAL_FUNCTION_PARAMETERS, int mode) {
                }
        }
 
-       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);
diff --git a/ext/dom/tests/bug50661.phpt b/ext/dom/tests/bug50661.phpt
new file mode 100644 (file)
index 0000000..dcea2c6
--- /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 = 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/>