1--TEST--
2Request #68325 (XML_OPTION_PARSE_HUGE cannot be set for xml_parser_create)
3--EXTENSIONS--
4xml
5--SKIPIF--
6<?php
7if (!defined("LIBXML_VERSION")) die('skip this is a libxml2 test');
8?>
9--FILE--
10<?php
11
12function logName(string $str) {
13    if (strlen($str) > 20) {
14        echo substr($str, 0, 20) . "...\n";
15    } else {
16        echo $str . "\n";
17    }
18}
19
20function createParser(bool $huge) {
21    $parser = xml_parser_create();
22    echo "old option value: "; var_dump(xml_parser_get_option($parser, XML_OPTION_PARSE_HUGE));
23    xml_parser_set_option($parser, XML_OPTION_PARSE_HUGE, $huge);
24    echo "new option value: "; var_dump(xml_parser_get_option($parser, XML_OPTION_PARSE_HUGE));
25    xml_set_element_handler($parser, function($parser, $data) {
26        echo "open: ";
27        logName($data);
28    }, function($parser, $data) {
29    });
30    return $parser;
31}
32
33// Construct XML that is too large to parse without XML_OPTION_PARSE_HUGE
34$long_text = str_repeat("A", 1000 * 1000 * 5 /* 5 MB */);
35$long_xml_head = "<?xml version=\"1.0\"?><container><$long_text/><$long_text/><second>foo</second>";
36$long_xml_tail = "</container>";
37
38echo "--- Parse using xml_parse (failure) ---\n";
39$parser = createParser(false);
40$ret = xml_parse($parser, $long_xml_head, true);
41echo "ret = $ret (", xml_error_string(xml_get_error_code($parser)), ")\n";
42
43echo "--- Parse using xml_parse (success) ---\n";
44$parser = createParser(true);
45$ret = xml_parse($parser, $long_xml_head, false);
46echo "ret = $ret (", xml_error_string(xml_get_error_code($parser)), ")\n";
47$ret = xml_parse($parser, $long_xml_tail, true);
48echo "ret = $ret (", xml_error_string(xml_get_error_code($parser)), ")\n";
49
50echo "--- Parse using xml_parse_into_struct (failure) ---\n";
51$parser = createParser(false);
52$ret = xml_parse_into_struct($parser, $long_xml_head, $values, $index);
53echo "ret = $ret (", xml_error_string(xml_get_error_code($parser)), ")\n";
54
55echo "--- Parse using xml_parse_into_struct (success) ---\n";
56$parser = createParser(true);
57$ret = xml_parse_into_struct($parser, $long_xml_head . $long_xml_tail, $values, $index);
58var_dump(count($values), count($index)); // Not printing out the raw array because the long string will be contained in them as key
59echo "ret = $ret (", xml_error_string(xml_get_error_code($parser)), ")\n";
60
61?>
62--EXPECT--
63--- Parse using xml_parse (failure) ---
64old option value: bool(false)
65new option value: bool(false)
66open: CONTAINER
67ret = 0 (XML_ERR_NAME_REQUIRED)
68--- Parse using xml_parse (success) ---
69old option value: bool(false)
70new option value: bool(true)
71open: CONTAINER
72open: AAAAAAAAAAAAAAAAAAAA...
73open: AAAAAAAAAAAAAAAAAAAA...
74open: SECOND
75ret = 1 (No error)
76ret = 1 (No error)
77--- Parse using xml_parse_into_struct (failure) ---
78old option value: bool(false)
79new option value: bool(false)
80open: CONTAINER
81ret = 0 (XML_ERR_NAME_REQUIRED)
82--- Parse using xml_parse_into_struct (success) ---
83old option value: bool(false)
84new option value: bool(true)
85open: CONTAINER
86open: AAAAAAAAAAAAAAAAAAAA...
87open: AAAAAAAAAAAAAAAAAAAA...
88open: SECOND
89int(5)
90int(3)
91ret = 1 (No error)
92