Skip to content

Commit 3ef5e89

Browse files
committed
Fix for broken null call (#177)
1 parent 0814819 commit 3ef5e89

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

src/Languages/Base/Injections/AdditionInjection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public function parse(string $content, Highlighter $highlighter): ParsedInjection
1717
{
1818
// Standardize line endings
19-
$content = preg_replace('/\R/u', PHP_EOL, $content);
19+
$content = preg_replace('/\R/u', PHP_EOL, $content) ?? '';
2020

2121
$content = str_replace('❷span class=❹ignore❹❸{+❷/span❸', '{+', $content);
2222
$content = str_replace('❷span class=❹ignore❹❸+}❷/span❸', '+}', $content);

src/Languages/Base/Injections/DeletionInjection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
public function parse(string $content, Highlighter $highlighter): ParsedInjection
1717
{
1818
// Standardize line endings
19-
$content = preg_replace('/\R/u', PHP_EOL, $content);
19+
$content = preg_replace('/\R/u', PHP_EOL, $content) ?? '';
2020

2121
$content = str_replace('❷span class=❹ignore❹❸{-❷/span❸', '{-', $content);
2222
$content = str_replace('❷span class=❹ignore❹❸-}❷/span❸', '-}', $content);

src/Languages/Base/Injections/GutterInjection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function addClass(int $line, string $class): self
3535

3636
public function parse(string $content, Highlighter $highlighter): ParsedInjection
3737
{
38-
$lines = preg_split('/\R/u', trim($content, "\n"));
38+
$lines = preg_split('/\R/u', trim($content, "\n")) ?? '';
3939

4040
$gutterNumbers = [];
4141
$longestGutterNumber = '';

tests/Languages/Base/Injections/AdditionInjectionTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,14 @@ public function test_addition_injection()
2525

2626
$this->assertSame($expected, Escape::html($parsedInjection->content));
2727
}
28+
29+
public function test_null_content_is_prevented(): void
30+
{
31+
$content = <<<TXT
32+
{~'_'~}
33+
TXT;
34+
new Highlighter()->parse($content, 'php');
35+
36+
$this->assertTrue(true);
37+
}
2838
}

tests/targets/test.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
```php
2-
try {
3-
} catch (HttpRequestFailed $failure) {
4-
}
2+
{~'_'~}
53
```

0 commit comments

Comments
 (0)