com php-src: fix bug related to #865: ext/spl/spl_iterators .c ext/spl/tests/bug68128-USE_KEY.phpt ext/ spl/tests/iterator_053.phpt
| From: | Nikita Popov | Date: | Thu, 22 Sep 2016 10:46:19 +0000 |
| Subject: | com php-src: fix bug related to #865: ext/spl/spl_iterators .c ext/spl/tests/bug68128-USE_KEY.phpt ext/ spl/tests/iterator_053.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94620@lists.php.net to get a copy of this message | ||
Commit: 4397306b322dc650a6d931bfecdb64cc56678c08
Author: Márcio Almada <marcio3w@gmail.com> Mon, 19 Sep 2016 12:42:07 -0400
Committer: Nikita Popov <nikic@php.net> Thu, 22 Sep 2016 12:46:19 +0200
Parents: 4dd70b6e2f40c0ad85bea761803f2aeeb8ef785a
Branches: PHP-5.6 PHP-7.0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=4397306b322dc650a6d931bfecdb64cc56678c08
Log:
fix bug related to #865
In case USE_KEY flag is active, RegexIterator->accept() should keep it's
old behavior which is to accept keys mapping arrays.
This broke after PHP 5.5 but was not noticed due to lack of tests for USE_KEY.
Bugs:
https://bugs.php.net/865
Changed paths:
M ext/spl/spl_iterators.c
A ext/spl/tests/bug68128-USE_KEY.phpt
M ext/spl/tests/iterator_053.phpt
Diff:
diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c
index a023b11..878e5a1 100644
--- a/ext/spl/spl_iterators.c
+++ b/ext/spl/spl_iterators.c
@@ -2053,13 +2053,14 @@ SPL_METHOD(RegexIterator, accept)
if (intern->current.data == NULL) {
RETURN_FALSE;
- } else if (Z_TYPE_P(intern->current.data) == IS_ARRAY) {
- RETURN_FALSE;
}
if (intern->u.regex.flags & REGIT_USE_KEY) {
subject_ptr = intern->current.key;
} else {
+ if (Z_TYPE_P(intern->current.data) == IS_ARRAY) {
+ RETURN_FALSE;
+ }
subject_ptr = intern->current.data;
}
diff --git a/ext/spl/tests/bug68128-USE_KEY.phpt b/ext/spl/tests/bug68128-USE_KEY.phpt
new file mode 100644
index 0000000..f5fcdae
--- /dev/null
+++ b/ext/spl/tests/bug68128-USE_KEY.phpt
@@ -0,0 +1,21 @@
+--TEST--
+Bug #68128 - RecursiveRegexIterator raises "Array to string conversion" notice
+--FILE--
+<?php
+
+$arrayIterator = new ArrayIterator(array('key 1' => 'value 1', 'key
2' => ['value 2']));
+$regexIterator = new RegexIterator($arrayIterator, '/^key/', RegexIterator::MATCH,
RegexIterator::USE_KEY);
+
+foreach ($regexIterator as $key => $value) {
+ var_dump($key, $value);
+}
+
+?>
+--EXPECT--
+string(5) "key 1"
+string(7) "value 1"
+string(5) "key 2"
+array(1) {
+ [0]=>
+ string(7) "value 2"
+}
diff --git a/ext/spl/tests/iterator_053.phpt b/ext/spl/tests/iterator_053.phpt
index b472523..21c044c 100644
--- a/ext/spl/tests/iterator_053.phpt
+++ b/ext/spl/tests/iterator_053.phpt
@@ -50,7 +50,7 @@ bool(true)
bool(true)
bool(true)
bool(true)
-bool(false)
+bool(true)
bool(true)
bool(true)
bool(true)
@@ -124,7 +124,20 @@ array(2) {
string(1) "4"
}
}
-bool(false)
+bool(true)
+int(5)
+array(2) {
+ [0]=>
+ array(1) {
+ [0]=>
+ string(1) "5"
+ }
+ [1]=>
+ array(1) {
+ [0]=>
+ string(1) "5"
+ }
+}
bool(true)
int(6)
array(2) {