@@ -29,3 +29,39 @@ function unmatchedAsNullWithOptionalGroup(string $s): void {
29
29
assertType ('array{}|array{string, string|null} ' , $ matches );
30
30
}
31
31
32
+ function bug11331a (string $ url ):void {
33
+ // group a is actually optional as the entire (?:...) around it is optional
34
+ if (preg_match ('{^
35
+ (?:
36
+ (?<a>.+)
37
+ )?
38
+ (?<b>.+)}mix ' , $ url , $ matches , PREG_UNMATCHED_AS_NULL )) {
39
+ assertType ('array{0: string, a: string|null, 1: string|null, b: string, 2: string} ' , $ matches );
40
+ }
41
+ }
42
+
43
+ function bug11331b (string $ url ):void {
44
+ if (preg_match ('{^
45
+ (?:
46
+ (?<a>.+)
47
+ )?
48
+ (?<b>.+)?}mix ' , $ url , $ matches , PREG_UNMATCHED_AS_NULL )) {
49
+ assertType ('array{0: string, a: string|null, 1: string|null, b: string|null, 2: string|null} ' , $ matches );
50
+ }
51
+ }
52
+
53
+ function bug11331c (string $ url ):void {
54
+ if (preg_match ('{^
55
+ (?:
56
+ (?:https?|git)://([^/]+)/ (?# group 1 here can be null if group 2 matches)
57
+ | (?# the alternation making it so that only either should match)
58
+ git@([^:]+):/? (?# group 2 here can be null if group 1 matches)
59
+ )
60
+ ([^/]+)
61
+ /
62
+ ([^/]+?)
63
+ (?:\.git|/)?
64
+ $}x ' , $ url , $ matches , PREG_UNMATCHED_AS_NULL )) {
65
+ assertType ('array{string, string|null, string|null, string, string} ' , $ matches );
66
+ }
67
+ }
0 commit comments