]> granicus.if.org Git - php/commitdiff
sync with 5.3 branch. add test for bug #44925
authorNuno Lopes <nlopess@php.net>
Thu, 14 Aug 2008 14:35:22 +0000 (14:35 +0000)
committerNuno Lopes <nlopess@php.net>
Thu, 14 Aug 2008 14:35:22 +0000 (14:35 +0000)
ext/pcre/php_pcre.c
ext/pcre/tests/bug44925.phpt [new file with mode: 0644]

index f1ee5585c32f4dd8c6b6856281c0846e68a1910a..18a08481acae7af8895659b57567baba75459205 100644 (file)
@@ -1976,9 +1976,8 @@ PHPAPI void  php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return
        /* Go through the input array */
        zend_hash_internal_pointer_reset(Z_ARRVAL_P(input));
        while(zend_hash_get_current_data(Z_ARRVAL_P(input), (void **)&entry) == SUCCESS) {
-               zval subject;
+               zval subject = **entry;
 
-               subject = **entry;
                if (Z_TYPE_PP(entry) != IS_STRING) {
                        zval_copy_ctor(&subject);
                        convert_to_string_with_converter(&subject, UG(utf8_conv));
@@ -2001,8 +2000,8 @@ PHPAPI void  php_pcre_grep_impl(pcre_cache_entry *pce, zval *input, zval *return
                }
 
                /* If the entry fits our requirements */
-               if ((count > 0 && !invert) ||
-                       (count == PCRE_ERROR_NOMATCH && invert)) {
+               if ((count > 0 && !invert) || (count == PCRE_ERROR_NOMATCH && invert)) {
+
                        Z_ADDREF_PP(entry);
 
                        /* Add to return array */
diff --git a/ext/pcre/tests/bug44925.phpt b/ext/pcre/tests/bug44925.phpt
new file mode 100644 (file)
index 0000000..84a3314
--- /dev/null
@@ -0,0 +1,107 @@
+--TEST--
+Bug #44925 (preg_grep() modifies input array)
+--FILE--
+<?php
+$str1 = 'a';
+$str2 = 'b';
+
+$array=Array("1",2,3,1.1,FALSE,NULL,Array(), $str1, &$str2);
+
+var_dump($array);
+
+var_dump(preg_grep('/do not match/',$array));
+
+$a = preg_grep('/./',$array);
+var_dump($a);
+
+$str1 = 'x';
+$str2 = 'y';
+
+var_dump($a); // check if array is still ok
+
+var_dump($array);
+
+?>
+--EXPECTF--
+array(9) {
+  [0]=>
+  unicode(1) "1"
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+  [3]=>
+  float(1.1)
+  [4]=>
+  bool(false)
+  [5]=>
+  NULL
+  [6]=>
+  array(0) {
+  }
+  [7]=>
+  unicode(1) "a"
+  [8]=>
+  &unicode(1) "b"
+}
+
+Notice: Array to string conversion in %sbug44925.php on line 9
+array(0) {
+}
+
+Notice: Array to string conversion in %sbug44925.php on line 11
+array(7) {
+  [0]=>
+  unicode(1) "1"
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+  [3]=>
+  float(1.1)
+  [6]=>
+  array(0) {
+  }
+  [7]=>
+  unicode(1) "a"
+  [8]=>
+  &unicode(1) "b"
+}
+array(7) {
+  [0]=>
+  unicode(1) "1"
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+  [3]=>
+  float(1.1)
+  [6]=>
+  array(0) {
+  }
+  [7]=>
+  unicode(1) "a"
+  [8]=>
+  &unicode(1) "y"
+}
+array(9) {
+  [0]=>
+  unicode(1) "1"
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+  [3]=>
+  float(1.1)
+  [4]=>
+  bool(false)
+  [5]=>
+  NULL
+  [6]=>
+  array(0) {
+  }
+  [7]=>
+  unicode(1) "a"
+  [8]=>
+  &unicode(1) "y"
+}