Skip to content

Commit

Permalink
Fix install error for some paths (#989)
Browse files Browse the repository at this point in the history
Fixes #988.

Instead of str_replace (which instead of truncating the leading directory from the path might replace some random inner part of it) use substr to remove it.
  • Loading branch information
singular0 authored Oct 19, 2023
1 parent 2ba6a1c commit f69164a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/system/classes/FileManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected function findFiles(string $basePath): array
*/
protected function getFilename(string $file): string
{
return str_replace($this->root, '', $file);
return substr($file, strlen($this->root));
}

/**
Expand Down
22 changes: 18 additions & 4 deletions modules/system/tests/classes/FileManifestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace System\Tests\Classes;

use ReflectionClass;

use System\Tests\Bootstrap\TestCase;
use Winter\Storm\Exception\ApplicationException;
use System\Classes\FileManifest;
Expand All @@ -11,14 +13,15 @@ class FileManifestTest extends TestCase
/** @var FileManifest instance */
protected $fileManifest;

/** @var root path */
protected $root;

public function setUp(): void
{
parent::setUp();

$this->fileManifest = new FileManifest(
base_path('modules/system/tests/fixtures/manifest/1_0_1'),
['test', 'test2']
);
$this->root = base_path('modules/system/tests/fixtures/manifest/1_0_1');
$this->fileManifest = new FileManifest($this->root, ['test', 'test2']);
}

public function testGetFiles()
Expand Down Expand Up @@ -61,4 +64,15 @@ public function testSingleModule()
'test' => 'c0b794ff210862a4ce16223802efe6e28969f5a4fb42480ec8c2fef2da23d181',
], $this->fileManifest->getModuleChecksums());
}

public function testGetFilename()
{
$class = new ReflectionClass('System\Classes\FileManifest');
$method = $class->getMethod('getFilename');
$method->setAccessible(true);

$filename = '/modules/test/file1.php';

$this->assertEquals($filename, $method->invoke($this->fileManifest, $this->root . $filename));
}
}

0 comments on commit f69164a

Please sign in to comment.