From cda4ae1f2d83c9472b6b49d2aca7381d4271aa4c Mon Sep 17 00:00:00 2001 From: sulimanbenhalim Date: Sat, 24 Oct 2026 22:39:55 +0200 Subject: [PATCH] fix: only end a PHP heredoc where its label starts a line --- .../Php/Injections/PhpHeredocInjection.php | 2 +- .../Php/Injections/HeredocInjectionTest.php | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Languages/Php/Injections/PhpHeredocInjection.php b/src/Languages/Php/Injections/PhpHeredocInjection.php index 56293425..88e3c83f 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 . '(?:;|\s|\))/', $content, $matches); + preg_match_all('/<<<' . $language . '(?(.|\n)*?\n[ \t]*)' . $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 61ca34db..2b8b31ab 100644 --- a/tests/Languages/Php/Injections/HeredocInjectionTest.php +++ b/tests/Languages/Php/Injections/HeredocInjectionTest.php @@ -74,4 +74,27 @@ public function sql_injection(): void currentLanguage: new PhpLanguage(), ); } + + #[Test] + public function label_inside_contents(): void + { + $content = ' +$query = <<assertMatches( + injection: new PhpHeredocInjection(), + content: $content, + expectedContent: $expected, + currentLanguage: new PhpLanguage(), + ); + } }