Skip to content

Commit ebf5902

Browse files
committed
1 parent 17cf7ca commit ebf5902

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

ext/xml/tests/toffset_bounds.phpt

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--TEST--
2+
XML_OPTION_SKIP_TAGSTART bounds
3+
--EXTENSIONS--
4+
xml
5+
--FILE--
6+
<?php
7+
$sample = "<?xml version=\"1.0\"?><test><child/></test>";
8+
$parser = xml_parser_create();
9+
xml_parser_set_option($parser, XML_OPTION_SKIP_TAGSTART, 100);
10+
$res = xml_parse_into_struct($parser,$sample,$vals,$index);
11+
var_dump($vals);
12+
?>
13+
--EXPECT--
14+
array(3) {
15+
[0]=>
16+
array(3) {
17+
["tag"]=>
18+
string(0) ""
19+
["type"]=>
20+
string(4) "open"
21+
["level"]=>
22+
int(1)
23+
}
24+
[1]=>
25+
array(3) {
26+
["tag"]=>
27+
string(0) ""
28+
["type"]=>
29+
string(8) "complete"
30+
["level"]=>
31+
int(2)
32+
}
33+
[2]=>
34+
array(3) {
35+
["tag"]=>
36+
string(0) ""
37+
["type"]=>
38+
string(5) "close"
39+
["level"]=>
40+
int(1)
41+
}
42+
}

ext/xml/xml.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,11 @@ void _xml_startElementHandler(void *userData, const XML_Char *name, const XML_Ch
657657
array_init(&tag);
658658
array_init(&atr);
659659

660-
_xml_add_to_info(parser, ZSTR_VAL(tag_name) + parser->toffset);
660+
char *skipped_tag_name = SKIP_TAGSTART(ZSTR_VAL(tag_name));
661661

662-
add_assoc_string(&tag, "tag", SKIP_TAGSTART(ZSTR_VAL(tag_name))); /* cast to avoid gcc-warning */
662+
_xml_add_to_info(parser, skipped_tag_name);
663+
664+
add_assoc_string(&tag, "tag", skipped_tag_name);
663665
add_assoc_string(&tag, "type", "open");
664666
add_assoc_long(&tag, "level", parser->level);
665667

@@ -741,12 +743,14 @@ void _xml_endElementHandler(void *userData, const XML_Char *name)
741743
add_assoc_string(zv, "type", "complete");
742744
}
743745
} else {
744-
_xml_add_to_info(parser, ZSTR_VAL(tag_name) + parser->toffset);
746+
char *skipped_tag_name = SKIP_TAGSTART(ZSTR_VAL(tag_name));
747+
748+
_xml_add_to_info(parser, skipped_tag_name);
745749

746750
zval *data = xml_get_separated_data(parser);
747751
if (EXPECTED(data)) {
748752
array_init(&tag);
749-
add_assoc_string(&tag, "tag", SKIP_TAGSTART(ZSTR_VAL(tag_name))); /* cast to avoid gcc-warning */
753+
add_assoc_string(&tag, "tag", skipped_tag_name);
750754
add_assoc_string(&tag, "type", "close");
751755
add_assoc_long(&tag, "level", parser->level);
752756
zend_hash_next_index_insert(Z_ARRVAL_P(data), &tag);

0 commit comments

Comments
 (0)