Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Languages/Php/Injections/PhpHeredocInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . '(?<match>(.|\n)*?)' . $language . '(?:;|\s|\))/', $content, $matches);
preg_match_all('/<<<' . $language . '(?<match>(.|\n)*?\n[ \t]*)' . $language . '(?:;|\s|\))/', $content, $matches);

foreach ($matches['match'] as $key => $match) {
$fullMatch = $matches[0][$key];
Expand Down
23 changes: 23 additions & 0 deletions tests/Languages/Php/Injections/HeredocInjectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,27 @@ public function sql_injection(): void
currentLanguage: new PhpLanguage(),
);
}

#[Test]
public function label_inside_contents(): void
{
$content = '
$query = <<<SQL
SELECT * FROM Book -- runs on MySQL and SQLite
SQL;
';

$expected = '
$query = &lt;&lt;&lt;<span class="hl-property">SQL</span>
<span class="hl-keyword">SELECT</span> * <span class="hl-keyword">FROM</span> <span class="hl-type">Book</span> <span class="hl-comment">-- runs on MySQL and SQLite</span>
<span class="hl-property">SQL</span>;
';

$this->assertMatches(
injection: new PhpHeredocInjection(),
content: $content,
expectedContent: $expected,
currentLanguage: new PhpLanguage(),
);
}
}
Loading