Respect OFFSET_CAPTURE when padding preg_match_all() results

This issue was mentioned in bug #73948. The PREG_PATTERN_ORDER
padding was performed without respecting the PREF_OFFSET_CAPTURE
flag, which resulted in unmatched subpatterns being either null or
[null, -1] depending on where they occur. Now they will always be
[null, -1], consistent with other usages.
This commit is contained in:
Nikita Popov 2019-03-19 15:35:15 +01:00
parent 2783670daa
commit f53e7394eb
3 changed files with 80 additions and 16 deletions

View file

@ -1290,7 +1290,11 @@ matched:
*/
if (count < num_subpats) {
for (; i < num_subpats; i++) {
if (unmatched_as_null) {
if (offset_capture) {
add_offset_pair(
&match_sets[i], NULL, 0, PCRE2_UNSET,
NULL, unmatched_as_null);
} else if (unmatched_as_null) {
add_next_index_null(&match_sets[i]);
} else {
add_next_index_str(&match_sets[i], ZSTR_EMPTY_ALLOC());