Skip to content

Commit

Permalink
Add more possessive quantifiers, unicode flag and support for more po…
Browse files Browse the repository at this point in the history
…st-heredoc syntax, fix test file syntax being invalid
  • Loading branch information
Seldaek committed Aug 29, 2021
1 parent 6ab1b6a commit 58ff7b5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Composer/Autoload/ClassMapGenerator.php
Expand Up @@ -248,19 +248,19 @@ private static function findClasses($path)
// 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 [\t \r\n]*[;,.)\]\}])[^\r\n]*+
# end of line(s)
[\r\n]+
[\r\n]++
)*
# end delimiter
[\t ]* \\2 (?=[\t \r\n]*[;,.)])
}x', 'null', $contents);
[\t ]*+ \\2 (?=[\t \r\n]*[;,.)\]\}])
}xu', 'null', $contents);

// strip strings
$contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents);
Expand Down
29 changes: 28 additions & 1 deletion tests/Composer/Test/Autoload/Fixtures/classmap/StripNoise.php
Expand Up @@ -23,7 +23,7 @@ class FailHeredocMarkerInText
{
}
But, what are you blind McFly, it's there. How else do you explain that wreck out there? Doc, Doc. Oh, no. You're alive. Bullet proof vest, how did you know, I never got a chance to tell you. About all that talk about screwing up future events, the space time continuum. Okay, alright, I'll prove it to you.
MARKERINTEXT
. MARKERINTEXT
class FailHeredocMarkerInText2
{
}
Expand Down Expand Up @@ -95,6 +95,33 @@ public function test_simple_string()
{
return 'class FailSimpleString {}';
}

public function test_unicode_heredoc()
{
return array(1, 2, <<<öéçив必
class FailUnicode
{
}
öéçив必, 3, 4);
}

public function test_wrapped_in_curly_brackets()
{
return ${<<<FOO
class FailCurlyBrackets
{
}
FOO};
}
public function test_wrapped_in_angle_brackets()
{
return [<<<FOO
class FailAngleBrackets
{
}
FOO];
}
}

// Issue #10067.
Expand Down

0 comments on commit 58ff7b5

Please sign in to comment.