1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-10 00:53:06 +00:00

Add more possessive quantifiers, unicode flag and support for more post-heredoc syntax, fix test file syntax being invalid

This commit is contained in:
Jordi Boggiano 2021-08-29 12:19:33 +02:00
parent 6ab1b6a7d2
commit d8054d1d2f
No known key found for this signature in database
GPG key ID: 7BBD42C429EC80BC
2 changed files with 33 additions and 6 deletions

View file

@ -248,19 +248,19 @@ class ClassMapGenerator
// strip heredocs/nowdocs
$contents = preg_replace('{
# opening heredoc/nowdoc delimiter (word-chars)
<<<[ \t]*([\'"]?)(\w+)\\1
<<<[ \t]*+([\'"]?)(\w++)\\1
# needs to be followed by a newline
(?:\r\n|\n|\r)
# the meat of it, matching line by line until end delimiter
(?:
# a valid line is optional white-space (possessive match) not followed by the end delimiter, then anything goes for the rest of the line
[\t ]*+(?!\\2 [\t \r\n]*[;,.)])[^\r\n]*
[\t ]*+(?!\\2 \b)[^\r\n]*+
# end of line(s)
[\r\n]+
[\r\n]++
)*
# end delimiter
[\t ]* \\2 (?=[\t \r\n]*[;,.)])
}x', 'null', $contents);
[\t ]*+ \\2 (?=\b)
}xu', 'null', $contents);
// strip strings
$contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents);