com php-src: Implement #47456: Missing PCRE option 'J': ext/pcre/php_pcre.c ext/pcre/tests/request47456 .phpt
| From: | Stanislav Malyshev | Date: | Mon, 05 Sep 2016 07:30:48 +0000 |
| Subject: | com php-src: Implement #47456: Missing PCRE option 'J': ext/pcre/php_pcre.c ext/pcre/tests/request47456 .phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94304@lists.php.net to get a copy of this message | ||
Commit: 39423e425d6caafea3c0b45c2b6ebe4a06a11462
Author: Christoph M. Becker <cmbecker69@gmx.de> Thu, 21 Jul 2016 15:36:42 +0200
Committer: Stanislav Malyshev <stas@php.net> Mon, 5 Sep 2016 00:30:48 -0700
Parents: cee363d6093abb25a3b0a0f448f8928c1f819294
Branches: PHP-5..6 PHP-7.0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=39423e425d6caafea3c0b45c2b6ebe4a06a11462
Log:
Implement #47456: Missing PCRE option 'J'
While it is possible to force the same behavior by setting the internal
option (?J), having a dedicated modifier appears to be useful. After all,
J is even listed on the "Pattern Modifiers" man page[1], but the description
referrs to (?J).
[1] <http://php.net/manual/en/reference.pcre.pattern.modifiers.php>
Bugs:
https://bugs.php.net/47456
Changed paths:
M ext/pcre/php_pcre.c
A ext/pcre/tests/request47456.phpt
Diff:
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index ddc5d76..21ea01d 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -396,6 +396,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_le
coptions |= PCRE_UCP;
#endif
break;
+ case 'J': coptions |= PCRE_DUPNAMES; break;
/* Custom preg options */
case 'e': poptions |= PREG_REPLACE_EVAL; break;
diff --git a/ext/pcre/tests/request47456.phpt b/ext/pcre/tests/request47456.phpt
new file mode 100644
index 0000000..2ba2627
--- /dev/null
+++ b/ext/pcre/tests/request47456.phpt
@@ -0,0 +1,101 @@
+--TEST--
+Request #47456 (Missing PCRE option 'J')
+--DESCRIPTION--
+The J modifier is supposed to be identical to the internal option (?J), so we're
+testing both.
+--FILE--
+<?php
+preg_match_all('/(?J)(?<chr>[ac])(?<num>\d)|(?<chr>[b])/',
'a1bc3', $m, PREG_SET_ORDER);
+var_dump($m);
+
+unset($m);
+preg_match_all('/(?<chr>[ac])(?<num>\d)|(?<chr>[b])/J',
'a1bc3', $m, PREG_SET_ORDER);
+var_dump($m);
+?>
+--EXPECT--
+array(3) {
+ [0]=>
+ array(5) {
+ [0]=>
+ string(2) "a1"
+ ["chr"]=>
+ string(1) "a"
+ [1]=>
+ string(1) "a"
+ ["num"]=>
+ string(1) "1"
+ [2]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(6) {
+ [0]=>
+ string(1) "b"
+ ["chr"]=>
+ string(1) "b"
+ [1]=>
+ string(0) ""
+ ["num"]=>
+ string(0) ""
+ [2]=>
+ string(0) ""
+ [3]=>
+ string(1) "b"
+ }
+ [2]=>
+ array(5) {
+ [0]=>
+ string(2) "c3"
+ ["chr"]=>
+ string(1) "c"
+ [1]=>
+ string(1) "c"
+ ["num"]=>
+ string(1) "3"
+ [2]=>
+ string(1) "3"
+ }
+}
+array(3) {
+ [0]=>
+ array(5) {
+ [0]=>
+ string(2) "a1"
+ ["chr"]=>
+ string(1) "a"
+ [1]=>
+ string(1) "a"
+ ["num"]=>
+ string(1) "1"
+ [2]=>
+ string(1) "1"
+ }
+ [1]=>
+ array(6) {
+ [0]=>
+ string(1) "b"
+ ["chr"]=>
+ string(1) "b"
+ [1]=>
+ string(0) ""
+ ["num"]=>
+ string(0) ""
+ [2]=>
+ string(0) ""
+ [3]=>
+ string(1) "b"
+ }
+ [2]=>
+ array(5) {
+ [0]=>
+ string(2) "c3"
+ ["chr"]=>
+ string(1) "c"
+ [1]=>
+ string(1) "c"
+ ["num"]=>
+ string(1) "3"
+ [2]=>
+ string(1) "3"
+ }
+}