svn: /php/php-src/ branches/PHP_5_3/NEWS branches/PHP_5_3/ext/spl/spl_iterators.c branches/PHP_5_3/ext/spl/tests/bug50579.phpt
trunk/ext/spl/spl_iterators.c trunk/ext/spl/tests/bug50579.phpt
| From: | Felipe Pena | Date: | Sat, 06 Nov 2010 00:09:50 +0000 |
| Subject: | svn: /php/php-src/ branches/PHP_5_3/NEWS branches/PHP_5_3/ext/spl/spl_iterators.c branches/PHP_5_3/ext/spl/tests/bug50579.phpt trunk/ext/spl/spl_iterators.c trunk/ext/spl/tests/bug50579.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-63767@lists.php.net to get a copy of this message | ||
felipe Sat, 06 Nov 2010 00:09:50 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=305121
Log:
- Fixed bug #50579 (RegexIterator::REPLACE doesn't work)
Bug: http://bugs.php.net/50579 (Verified)
RegexIterator::REPLACE doesn't work
Changed paths:
U php/php-src/branches/PHP_5_3/NEWS
U php/php-src/branches/PHP_5_3/ext/spl/spl_iterators.c
A php/php-src/branches/PHP_5_3/ext/spl/tests/bug50579.phpt
U php/php-src/trunk/ext/spl/spl_iterators.c
A php/php-src/trunk/ext/spl/tests/bug50579.phpt
Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS 2010-11-05 23:56:36 UTC (rev 305120)
+++ php/php-src/branches/PHP_5_3/NEWS 2010-11-06 00:09:50 UTC (rev 305121)
@@ -166,6 +166,7 @@
(a_jelly_doughnut at phpbb dot com, Pierre)
- Fixed bug #50953 (socket will not connect to IPv4 address when the host has
both IPv4 and IPv6 addresses, on Windows). (Gustavo, Pierre)
+- Fixed bug #50579 (RegexIterator::REPLACE doesn't work). (Felipe)
- Fixed bug #50524 (proc_open on Windows does not respect cwd as it does on
other platforms). (Pierre)
- Fixed bug #50345 (nanosleep not detected properly on some solaris versions).
Modified: php/php-src/branches/PHP_5_3/ext/spl/spl_iterators.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/spl/spl_iterators.c 2010-11-05 23:56:36 UTC (rev 305120)
+++ php/php-src/branches/PHP_5_3/ext/spl/spl_iterators.c 2010-11-06 00:09:50 UTC (rev 305121)
@@ -1733,7 +1733,7 @@
{
spl_dual_it_object *intern = (spl_dual_it_object*)zend_object_store_get_object(getThis()
TSRMLS_CC);
char *subject, tmp[32], *result;
- int subject_len, use_copy, count, result_len;
+ int subject_len, use_copy, count = 0, result_len;
zval subject_copy, zcount, *replacement;
if (intern->current.data == NULL) {
@@ -1796,8 +1796,8 @@
break;
case REGIT_MODE_REPLACE:
- replacement = zend_read_property(intern->std.ce, getThis(), "replacement",
sizeof("replacement")-1, 1 TSRMLS_CC);
- result = php_pcre_replace_impl(intern->u.regex.pce, subject, subject_len, replacement, 0,
&result_len, 0, NULL TSRMLS_CC);
+ replacement = zend_read_property(intern->std.ce, intern->inner.zobject,
"replacement", sizeof("replacement")-1, 1 TSRMLS_CC);
+ result = php_pcre_replace_impl(intern->u.regex.pce, subject, subject_len, replacement, 0,
&result_len, -1, &count TSRMLS_CC);
if (intern->u.regex.flags & REGIT_USE_KEY) {
if (intern->current.key_type != HASH_KEY_IS_LONG) {
@@ -1811,6 +1811,7 @@
MAKE_STD_ZVAL(intern->current.data);
ZVAL_STRINGL(intern->current.data, result, result_len, 0);
}
+ RETVAL_BOOL(count > 0);
}
if (intern->u.regex.flags & REGIT_INVERTED) {
Added: php/php-src/branches/PHP_5_3/ext/spl/tests/bug50579.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/spl/tests/bug50579.phpt (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/spl/tests/bug50579.phpt 2010-11-06 00:09:50 UTC (rev 305121)
@@ -0,0 +1,40 @@
+--TEST--
+Bug #50579 (RegexIterator::REPLACE doesn't work)
+--FILE--
+<?php
+
+class foo extends ArrayIterator {
+ public function __construct( ) {
+ parent::__construct(array(
+ 'test1'=>'test888',
+ 'test2'=>'what?',
+ 'test3'=>'test999'));
+ $this->replacement = '[$1]';
+ }
+}
+$h = new foo;
+$i = new RegexIterator($h, '/^test(.*)/', RegexIterator::REPLACE);
+$h->replacement = '[$0]';
+foreach ($i as $name=>$value) {
+ echo $name . '=>' . $value . "\n";
+}
+
+$h->replacement = '$1';
+foreach ($i as $name=>$value) {
+ echo $name . '=>' . $value . "\n";
+}
+
+$h = new foo;
+$i = new RegexIterator($h, '/^test(.*)/', RegexIterator::REPLACE);
+foreach ($i as $name=>$value) {
+ echo $name . '=>' . $value . "\n";
+}
+
+?>
+--EXPECTF--
+test1=>[test888]
+test3=>[test999]
+test1=>888
+test3=>999
+test1=>[888]
+test3=>[999]
Property changes on: php/php-src/branches/PHP_5_3/ext/spl/tests/bug50579.phpt
___________________________________________________________________
Added: svn:keywords
+ Id Rev Revision
Added: svn:eol-style
+ native
Modified: php/php-src/trunk/ext/spl/spl_iterators.c
===================================================================
--- php/php-src/trunk/ext/spl/spl_iterators.c 2010-11-05 23:56:36 UTC (rev 305120)
+++ php/php-src/trunk/ext/spl/spl_iterators.c 2010-11-06 00:09:50 UTC (rev 305121)
@@ -1732,7 +1732,7 @@
{
spl_dual_it_object *intern = (spl_dual_it_object*)zend_object_store_get_object(getThis()
TSRMLS_CC);
char *subject, tmp[32], *result;
- int subject_len, use_copy, count, result_len;
+ int subject_len, use_copy, count = 0, result_len;
zval subject_copy, zcount, *replacement;
if (intern->current.data == NULL) {
@@ -1795,8 +1795,8 @@
break;
case REGIT_MODE_REPLACE:
- replacement = zend_read_property(intern->std.ce, getThis(), "replacement",
sizeof("replacement")-1, 1 TSRMLS_CC);
- result = php_pcre_replace_impl(intern->u.regex.pce, subject, subject_len, replacement, 0,
&result_len, 0, NULL TSRMLS_CC);
+ replacement = zend_read_property(intern->std.ce, intern->inner.zobject,
"replacement", sizeof("replacement")-1, 1 TSRMLS_CC);
+ result = php_pcre_replace_impl(intern->u.regex.pce, subject, subject_len, replacement, 0,
&result_len, -1, &count TSRMLS_CC);
if (intern->u.regex.flags & REGIT_USE_KEY) {
if (intern->current.key_type != HASH_KEY_IS_LONG) {
@@ -1810,6 +1810,7 @@
MAKE_STD_ZVAL(intern->current.data);
ZVAL_STRINGL(intern->current.data, result, result_len, 0);
}
+ RETVAL_BOOL(count > 0);
}
if (intern->u.regex.flags & REGIT_INVERTED) {
Added: php/php-src/trunk/ext/spl/tests/bug50579.phpt
===================================================================
--- php/php-src/trunk/ext/spl/tests/bug50579.phpt (rev 0)
+++ php/php-src/trunk/ext/spl/tests/bug50579.phpt 2010-11-06 00:09:50 UTC (rev 305121)
@@ -0,0 +1,40 @@
+--TEST--
+Bug #50579 (RegexIterator::REPLACE doesn't work)
+--FILE--
+<?php
+
+class foo extends ArrayIterator {
+ public function __construct( ) {
+ parent::__construct(array(
+ 'test1'=>'test888',
+ 'test2'=>'what?',
+ 'test3'=>'test999'));
+ $this->replacement = '[$1]';
+ }
+}
+$h = new foo;
+$i = new RegexIterator($h, '/^test(.*)/', RegexIterator::REPLACE);
+$h->replacement = '[$0]';
+foreach ($i as $name=>$value) {
+ echo $name . '=>' . $value . "\n";
+}
+
+$h->replacement = '$1';
+foreach ($i as $name=>$value) {
+ echo $name . '=>' . $value . "\n";
+}
+
+$h = new foo;
+$i = new RegexIterator($h, '/^test(.*)/', RegexIterator::REPLACE);
+foreach ($i as $name=>$value) {
+ echo $name . '=>' . $value . "\n";
+}
+
+?>
+--EXPECTF--
+test1=>[test888]
+test3=>[test999]
+test1=>888
+test3=>999
+test1=>[888]
+test3=>[999]
Property changes on: php/php-src/trunk/ext/spl/tests/bug50579.phpt
___________________________________________________________________
Added: svn:keywords
+ Id Rev Revision
Added: svn:eol-style
+ native