Skip to content

Commit

Permalink
Ignore invalid PHARs (#2604)
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Mar 17, 2024
1 parent aa9907f commit 882b12b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/Indexer/Model/IndexJob.php
Expand Up @@ -2,13 +2,13 @@

namespace Phpactor\Indexer\Model;

use FilesystemIterator;
use Generator;
use Phar;
use PharFileInfo;
use Phpactor\TextDocument\TextDocumentBuilder;
use RecursiveIteratorIterator;
use SplFileInfo;
use UnexpectedValueException;

class IndexJob
{
Expand All @@ -24,10 +24,17 @@ public function generator(): Generator

foreach ($this->fileList as $fileInfo) {
assert($fileInfo instanceof SplFileInfo);
if ($fileInfo->isLink()) {
continue;
}

// TODO: could refactor this to iterate the PHAR in the file list provider.
if ($fileInfo->getExtension() === 'phar') {
$phar = new Phar($fileInfo->getPathname(), FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME);
try {
$phar = new Phar($fileInfo->getPathname());
} catch (UnexpectedValueException $e) {
continue;
}
yield from $this->indexPharFile($phar);
continue;
}
Expand Down
9 changes: 9 additions & 0 deletions lib/Indexer/Tests/Adapter/PharIndexTest.php
Expand Up @@ -32,4 +32,13 @@ public function testIndexPhar(): void
self::assertCount(1, $hellos);
}

public function testIndexInvalidPhar(): void
{
$this->workspace()->put('repo/index.phar', '<?php class Hello{}');

$agent = $this->indexAgentBuilder('repo')->buildTestAgent();
$agent->indexer()->getJob()->run();
$hellos = iterator_to_array($agent->search()->search(Criteria::shortNameContains('Hello')));
self::assertCount(0, $hellos);
}
}

0 comments on commit 882b12b

Please sign in to comment.