diff --git a/src/Languages/Php/Injections/PhpHeredocInjection.php b/src/Languages/Php/Injections/PhpHeredocInjection.php index 01c403d..5629342 100644 --- a/src/Languages/Php/Injections/PhpHeredocInjection.php +++ b/src/Languages/Php/Injections/PhpHeredocInjection.php @@ -22,7 +22,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio // First we'll search for all Heredoc open tags, // which we need in order to find the close tag, and so the whole Heredoc block foreach ($languageMatches['language'] as $language) { - preg_match_all('/<<<' . $language . '(?(.|\n)*?)' . $language . ';/', $content, $matches); + preg_match_all('/<<<' . $language . '(?(.|\n)*?)' . $language . '(?:;|\s|\))/', $content, $matches); foreach ($matches['match'] as $key => $match) { $fullMatch = $matches[0][$key]; diff --git a/tests/Languages/Php/Injections/HeredocInjectionTest.php b/tests/Languages/Php/Injections/HeredocInjectionTest.php index e53bc47..61ca34d 100644 --- a/tests/Languages/Php/Injections/HeredocInjectionTest.php +++ b/tests/Languages/Php/Injections/HeredocInjectionTest.php @@ -44,4 +44,34 @@ public function test_injection(): void currentLanguage: new PhpLanguage(), ); } + + #[Test] + public function sql_injection(): void + { + + $content = ' +$books = map(new Query(<<collection()->to(Book::class); + '; + + $expected = ' +$books = map(new Query(<<<SQL + SELECT * + FROM Book + LEFT JOIN … + HAVING … +SQL))->collection()->to(Book::class); + '; + + $this->assertMatches( + injection: new PhpHeredocInjection(), + content: $content, + expectedContent: $expected, + currentLanguage: new PhpLanguage(), + ); + } }