Skip to content

Commit 4afadf6

Browse files
committed
Fix handling of actual newlines in regexes, refs #11360
1 parent 4d055b0 commit 4afadf6

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

resources/RegexGrammar.pp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,6 @@
4141
// @license New BSD License
4242
//
4343

44-
45-
// Skip.
46-
%skip nl \n
47-
4844
// Character classes.
4945
%token negative_class_ \[\^ -> class
5046
%token class_ \[ -> class
@@ -58,7 +54,7 @@
5854
%token class:character \\([aefnrtb]|c[\x00-\x7f])
5955
%token class:dynamic_character \\([0-7]{3}|x[0-9a-zA-Z]{2}|x{[0-9a-zA-Z]+})
6056
%token class:character_type \\([CdDhHNRsSvVwWX]|[pP]{[^}]+})
61-
%token class:literal \\.|.
57+
%token class:literal \\.|.|\n
6258

6359
// Internal options.
6460
// See https://www.regular-expressions.info/refmodifiers.html
@@ -122,7 +118,7 @@
122118
%token character_type \\([CdDhHNRsSvVwWX]|[pP]{[^}]+})
123119
%token anchor \\([bBAZzG])|\^|\$
124120
%token match_point_reset \\K
125-
%token literal \\.|.
121+
%token literal \\.|.|\n
126122

127123

128124
// Rules.

tests/PHPStan/Analyser/nsrt/preg_match_shapes.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ function bug11323(string $s): void {
518518
if (preg_match('{([^1-4])}', $s, $matches)) {
519519
assertType('array{string, non-empty-string}', $matches);
520520
}
521+
if (preg_match("{([\r\n]+)(\n)([\n])}", $s, $matches)) {
522+
assertType('array{string, non-empty-string, non-empty-string, non-empty-string}', $matches);
523+
}
521524
}
522525

523526
function (string $s): void {

0 commit comments

Comments
 (0)