com php-src: Respect OFFSET_CAPTURE when padding preg _match_all() results: ext/pcre/php_pcre.c e xt/pcre/tests/bug61780_1.phpt ext/pcre/tests/
bug61780_2.phpt
| From: | Nikita Popov | Date: | Tue, 19 Mar 2019 14:35:15 +0000 |
| Subject: | com php-src: Respect OFFSET_CAPTURE when padding preg _match_all() results: ext/pcre/php_pcre.c e xt/pcre/tests/bug61780_1.phpt ext/pcre/tests/ bug61780_2.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-105248@lists.php.net to get a copy of this message | ||
Commit: f53e7394eb61085c09928b47f84123bd90b64dfb
Author: Nikita Popov <nikita.ppv@gmail.com> Tue, 19 Mar 2019 15:35:15 +0100
Parents: 2783670daa7831b61937ab91f5d2cd84d63de5fd
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f53e7394eb61085c09928b47f84123bd90b64dfb
Log:
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.
Bugs:
https://bugs..php.net/73948
Changed paths:
M ext/pcre/php_pcre.c
M ext/pcre/tests/bug61780_1.phpt
M ext/pcre/tests/bug61780_2.phpt
Diff:
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index 37e0b0c...bdc2998 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -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());
diff --git a/ext/pcre/tests/bug61780_1.phpt b/ext/pcre/tests/bug61780_1.phpt
index dc5806c..932f43f 100644
--- a/ext/pcre/tests/bug61780_1.phpt
+++ b/ext/pcre/tests/bug61780_1.phpt
@@ -95,7 +95,11 @@ array (
),
1 =>
array (
- 0 => NULL,
+ 0 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
1 =>
array (
0 => NULL,
@@ -106,18 +110,34 @@ array (
0 => '4',
1 => 3,
),
- 3 => NULL,
+ 3 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
),
2 =>
array (
- 0 => NULL,
+ 0 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
1 =>
array (
0 => '2',
1 => 1,
),
- 2 => NULL,
- 3 => NULL,
+ 2 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
+ 3 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
),
)
diff --git a/ext/pcre/tests/bug61780_2.phpt b/ext/pcre/tests/bug61780_2.phpt
index faf44d3..acc3e96 100644
--- a/ext/pcre/tests/bug61780_2.phpt
+++ b/ext/pcre/tests/bug61780_2.phpt
@@ -121,7 +121,11 @@ array (
),
'a' =>
array (
- 0 => NULL,
+ 0 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
1 =>
array (
0 => NULL,
@@ -132,11 +136,19 @@ array (
0 => '4',
1 => 3,
),
- 3 => NULL,
+ 3 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
),
1 =>
array (
- 0 => NULL,
+ 0 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
1 =>
array (
0 => NULL,
@@ -147,29 +159,57 @@ array (
0 => '4',
1 => 3,
),
- 3 => NULL,
+ 3 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
),
'b' =>
array (
- 0 => NULL,
+ 0 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
1 =>
array (
0 => '2',
1 => 1,
),
- 2 => NULL,
- 3 => NULL,
+ 2 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
+ 3 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
),
2 =>
array (
- 0 => NULL,
+ 0 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
1 =>
array (
0 => '2',
1 => 1,
),
- 2 => NULL,
- 3 => NULL,
+ 2 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
+ 3 =>
+ array (
+ 0 => NULL,
+ 1 => -1,
+ ),
),
)