Skip to content

Commit 39423e4

Browse files
cmb69smalyshev
authored andcommitted
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>
1 parent cee363d commit 39423e4

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed

ext/pcre/php_pcre.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ PHPAPI pcre_cache_entry* pcre_get_compiled_regex_cache(char *regex, int regex_le
396396
coptions |= PCRE_UCP;
397397
#endif
398398
break;
399+
case 'J': coptions |= PCRE_DUPNAMES; break;
399400

400401
/* Custom preg options */
401402
case 'e': poptions |= PREG_REPLACE_EVAL; break;

ext/pcre/tests/request47456.phpt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
--TEST--
2+
Request #47456 (Missing PCRE option 'J')
3+
--DESCRIPTION--
4+
The J modifier is supposed to be identical to the internal option (?J), so we're
5+
testing both.
6+
--FILE--
7+
<?php
8+
preg_match_all('/(?J)(?<chr>[ac])(?<num>\d)|(?<chr>[b])/', 'a1bc3', $m, PREG_SET_ORDER);
9+
var_dump($m);
10+
11+
unset($m);
12+
preg_match_all('/(?<chr>[ac])(?<num>\d)|(?<chr>[b])/J', 'a1bc3', $m, PREG_SET_ORDER);
13+
var_dump($m);
14+
?>
15+
--EXPECT--
16+
array(3) {
17+
[0]=>
18+
array(5) {
19+
[0]=>
20+
string(2) "a1"
21+
["chr"]=>
22+
string(1) "a"
23+
[1]=>
24+
string(1) "a"
25+
["num"]=>
26+
string(1) "1"
27+
[2]=>
28+
string(1) "1"
29+
}
30+
[1]=>
31+
array(6) {
32+
[0]=>
33+
string(1) "b"
34+
["chr"]=>
35+
string(1) "b"
36+
[1]=>
37+
string(0) ""
38+
["num"]=>
39+
string(0) ""
40+
[2]=>
41+
string(0) ""
42+
[3]=>
43+
string(1) "b"
44+
}
45+
[2]=>
46+
array(5) {
47+
[0]=>
48+
string(2) "c3"
49+
["chr"]=>
50+
string(1) "c"
51+
[1]=>
52+
string(1) "c"
53+
["num"]=>
54+
string(1) "3"
55+
[2]=>
56+
string(1) "3"
57+
}
58+
}
59+
array(3) {
60+
[0]=>
61+
array(5) {
62+
[0]=>
63+
string(2) "a1"
64+
["chr"]=>
65+
string(1) "a"
66+
[1]=>
67+
string(1) "a"
68+
["num"]=>
69+
string(1) "1"
70+
[2]=>
71+
string(1) "1"
72+
}
73+
[1]=>
74+
array(6) {
75+
[0]=>
76+
string(1) "b"
77+
["chr"]=>
78+
string(1) "b"
79+
[1]=>
80+
string(0) ""
81+
["num"]=>
82+
string(0) ""
83+
[2]=>
84+
string(0) ""
85+
[3]=>
86+
string(1) "b"
87+
}
88+
[2]=>
89+
array(5) {
90+
[0]=>
91+
string(2) "c3"
92+
["chr"]=>
93+
string(1) "c"
94+
[1]=>
95+
string(1) "c"
96+
["num"]=>
97+
string(1) "3"
98+
[2]=>
99+
string(1) "3"
100+
}
101+
}

0 commit comments

Comments
 (0)