com php-src: fixed bug66702 : regexiterator's invert flag doesn't work as expected: ext/spl/spl_iterators.c ext/spl/tests/bug66 702.phpt
| From: | Etienne Kneuss | Date: | Wed, 09 Apr 2014 09:13:33 +0000 |
| Subject: | com php-src: fixed bug66702 : regexiterator's invert flag doesn't work as expected: ext/spl/spl_iterators.c ext/spl/tests/bug66 702.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-76736@lists.php.net to get a copy of this message | ||
Commit: e8d6c6587d53b112d68d1cbb9dc4af0604310437
Author: Joshua Thijssen <jthijssen@noxlogic.nl> Wed, 12 Feb 2014 21:28:20 +0100
Committer: Etienne Kneuss <colder@php.net> Wed, 9 Apr 2014 11:13:33 +0200
Parents: 032921d80cd97d1d8a696348ce6bb0fd17e597e8
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e8d6c6587d53b112d68d1cbb9dc4af0604310437
Log:
fixed bug66702 : regexiterator's invert flag doesn't work as expected
Bugs:
https://bugs.php..net/66702
Changed paths:
M ext/spl/spl_iterators.c
A ext/spl/tests/bug66702.phpt
Diff:
diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c
index 2517366..047b47f 100644
--- a/ext/spl/spl_iterators.c
+++ b/ext/spl/spl_iterators.c
@@ -2055,7 +2055,7 @@ SPL_METHOD(RegexIterator, accept)
}
if (intern->u.regex.flags & REGIT_INVERTED) {
- RETVAL_BOOL(Z_LVAL_P(return_value));
+ RETVAL_BOOL(! Z_LVAL_P(return_value));
}
if (use_copy) {
@@ -3692,6 +3692,7 @@ PHP_MINIT_FUNCTION(spl_iterators)
#if HAVE_PCRE || HAVE_BUNDLED_PCRE
REGISTER_SPL_SUB_CLASS_EX(RegexIterator, FilterIterator, spl_dual_it_new,
spl_funcs_RegexIterator);
REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "USE_KEY", REGIT_USE_KEY);
+ REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "INVERT_MATCH",REGIT_INVERTED);
REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "MATCH", REGIT_MODE_MATCH);
REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "GET_MATCH", REGIT_MODE_GET_MATCH);
REGISTER_SPL_CLASS_CONST_LONG(RegexIterator, "ALL_MATCHES", REGIT_MODE_ALL_MATCHES);
diff --git a/ext/spl/tests/bug66702.phpt b/ext/spl/tests/bug66702.phpt
new file mode 100644
index 0000000..fedfc86
--- /dev/null
+++ b/ext/spl/tests/bug66702.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Bug #66702 (RegexIterator inverted result works as expected)
+--FILE--
+<?php
+/**
+ * @author Joshua Thijssen <jthijssen+php@noxlogic.nl>
+ */
+
+$it = new \ArrayIterator(array("foo", "bar", "baz"));
+$it2 = new \RegexIterator($it, "/^ba/", \RegexIterator::MATCH);
+print_r(iterator_to_array($it2));
+$it2 = new \RegexIterator($it, "/^ba/", \RegexIterator::MATCH,
\RegexIterator::INVERT_MATCH);
+print_r(iterator_to_array($it2));
+
+$it = new \ArrayIterator(array("foo" => 1, "bar" => 2, "baz"
=> 3));
+$it2 = new \RegexIterator($it, "/^ba/", \RegexIterator::MATCH, \RegexIterator::USE_KEY);
+print_r(iterator_to_array($it2));
+$it2 = new \RegexIterator($it, "/^ba/", \RegexIterator::MATCH, \RegexIterator::USE_KEY |
\RegexIterator::INVERT_MATCH);
+print_r(iterator_to_array($it2));
+
+--EXPECTF--
+Array
+(
+ [1] => bar
+ [2] => baz
+)
+Array
+(
+ [0] => foo
+)
+Array
+(
+ [bar] => 2
+ [baz] => 3
+)
+Array
+(
+ [foo] => 1
+)
+