Skip to content

Commit 5817a0e

Browse files
committed
Fix null passed to strlen in parsers
When a command is run and fails it returns null. This is then passed to the parser and it handles it as an empty string Since PHP 8.0 it is deprecated to pass null to `strlen` so instead make this an empty String.
1 parent fae9911 commit 5817a0e

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/Gitonomy/Git/Parser/ParserBase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract protected function doParse();
2525
public function parse($content)
2626
{
2727
$this->cursor = 0;
28-
$this->content = $content;
28+
$this->content = $content ?? '';
2929
$this->length = strlen($this->content);
3030

3131
$this->doParse();

src/Gitonomy/Git/ReferenceBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ protected function initialize()
354354
$parser = new Parser\ReferenceParser();
355355
$output = $this->repository->run('show-ref');
356356
} catch (RuntimeException $e) {
357-
$output = null;
357+
return;
358358
}
359359
$parser->parse($output);
360360

tests/Gitonomy/Git/Tests/ReferenceBagTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,13 @@ public function testUnknownReference(Repository $repository)
4444
$this->assertArrayNotHasKey('refs/pull/1/head', $refs);
4545
$this->assertArrayNotHasKey('refs/notes/gtm-data', $refs);
4646
}
47+
48+
/**
49+
* @dataProvider provideEmpty
50+
*/
51+
public function testEmptyRepo(Repository $repository)
52+
{
53+
$refs = $repository->getReferences()->getAll();
54+
$this->assertSame([], $refs);
55+
}
4756
}

0 commit comments

Comments
 (0)