Skip to content

Commit 5db1c09

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 5db1c09

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace Gitonomy\Git\Tests;
1414

15+
use Gitonomy\Git\Admin;
1516
use Gitonomy\Git\Repository;
1617

1718
class ReferenceBagTest extends AbstractTest
@@ -44,4 +45,13 @@ public function testUnknownReference(Repository $repository)
4445
$this->assertArrayNotHasKey('refs/pull/1/head', $refs);
4546
$this->assertArrayNotHasKey('refs/notes/gtm-data', $refs);
4647
}
48+
49+
/**
50+
* @dataProvider provideEmpty
51+
*/
52+
public function testEmptyRepo(Repository $repository)
53+
{
54+
$refs = $repository->getReferences()->getAll();
55+
$this->assertSame([], $refs);
56+
}
4757
}

0 commit comments

Comments
 (0)