]> granicus.if.org Git - php/commitdiff
Respect OFFSET_CAPTURE when padding preg_match_all() results
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 19 Mar 2019 14:35:15 +0000 (15:35 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 19 Mar 2019 14:35:15 +0000 (15:35 +0100)
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.

ext/pcre/php_pcre.c
ext/pcre/tests/bug61780_1.phpt
ext/pcre/tests/bug61780_2.phpt

index 37e0b0c68b3e3ab44c01285118ccd1edad99030d..bdc299806cda4fd5318bcefa9dde8ad28be3d025 100644 (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());
index dc5806cb30e40e7f7a25c66e407d55018c00a82b..932f43ffd6a9d1f1c6e395318276e6d733681eef 100644 (file)
@@ -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,
+    ),
   ),
 )
 
index faf44d368bef7688d8995e4efca9ac2058190092..acc3e96e898901a1a0bb24ec29060403675b0c2d 100644 (file)
@@ -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,
+    ),
   ),
 )