From: Felipe Pena Date: Sat, 6 Nov 2010 00:09:50 +0000 (+0000) Subject: - Fixed bug #50579 (RegexIterator::REPLACE doesn't work) X-Git-Tag: php-5.3.4RC1~77 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7636635ec5d66ee422d2d2c34b4febb5b768d808;p=php - Fixed bug #50579 (RegexIterator::REPLACE doesn't work) --- diff --git a/NEWS b/NEWS index c9098d7a75..0bce8965c7 100644 --- a/NEWS +++ b/NEWS @@ -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). diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 64d783db0f..dc6f17bac0 100755 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -1733,7 +1733,7 @@ SPL_METHOD(RegexIterator, accept) { 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 @@ SPL_METHOD(RegexIterator, accept) 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 @@ SPL_METHOD(RegexIterator, accept) 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) { diff --git a/ext/spl/tests/bug50579.phpt b/ext/spl/tests/bug50579.phpt new file mode 100644 index 0000000000..3045228ef0 --- /dev/null +++ b/ext/spl/tests/bug50579.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #50579 (RegexIterator::REPLACE doesn't work) +--FILE-- +'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]