mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-28 00:01:27 +02:00
Fixed broken parent directory links for directories named '0'
This commit is contained in:
@@ -35,8 +35,14 @@ class ParentUrl extends ViewFunction
|
||||
function (string $segment): string {
|
||||
return rawurlencode($segment);
|
||||
}
|
||||
)->filter()->slice(0, -1)->implode($this->directorySeparator);
|
||||
)->filter(function ($value): bool {
|
||||
return $value !== null;
|
||||
})->slice(0, -1)->implode($this->directorySeparator);
|
||||
|
||||
return empty($parentDir) ? '.' : sprintf('?dir=%s', $parentDir);
|
||||
if ($parentDir === '') {
|
||||
return '.';
|
||||
}
|
||||
|
||||
return sprintf('?dir=%s', $parentDir);
|
||||
}
|
||||
}
|
||||
|
@@ -7,41 +7,25 @@ use Tests\TestCase;
|
||||
|
||||
class ParentUrlTest extends TestCase
|
||||
{
|
||||
public function test_it_can_get_the_parent_directory_when_one_level_deep(): void
|
||||
public function test_it_can_get_the_parent_directory(): void
|
||||
{
|
||||
$parentDir = new ParentUrl;
|
||||
|
||||
$this->assertEquals('.', $parentDir('foo'));
|
||||
}
|
||||
|
||||
public function test_it_can_get_the_parent_directory_when_two_levels_deep(): void
|
||||
{
|
||||
$parentDir = new ParentUrl;
|
||||
|
||||
$this->assertEquals('?dir=foo', $parentDir('foo/bar'));
|
||||
}
|
||||
|
||||
public function test_it_can_get_the_parent_directory_when_three_levels_deep(): void
|
||||
{
|
||||
$parentDir = new ParentUrl;
|
||||
|
||||
$this->assertEquals('?dir=foo/bar', $parentDir('foo/bar/baz'));
|
||||
}
|
||||
|
||||
public function test_it_can_get_the_parent_directory_from_a_path_in_a_subdirectory(): void
|
||||
{
|
||||
$_SERVER['SCRIPT_NAME'] = '/some/dir/index.php';
|
||||
|
||||
$parentDir = new ParentUrl;
|
||||
|
||||
$this->assertEquals('?dir=foo/bar', $parentDir('foo/bar/baz'));
|
||||
$this->assertEquals('?dir=foo/0', $parentDir('foo/0/bar'));
|
||||
$this->assertEquals('?dir=0', $parentDir('0/bar'));
|
||||
}
|
||||
|
||||
public function test_it_can_get_the_parent_directory_with_back_slashes(): void
|
||||
{
|
||||
$parentDir = new ParentUrl('\\');
|
||||
|
||||
$this->assertEquals('?dir=foo', $parentDir('foo\bar'));
|
||||
$this->assertEquals('?dir=foo\bar', $parentDir('foo\bar\baz'));
|
||||
$this->assertEquals('?dir=foo\0', $parentDir('foo\0\bar'));
|
||||
$this->assertEquals('?dir=0', $parentDir('0\bar'));
|
||||
}
|
||||
|
||||
public function test_parent_url_segments_are_url_encoded(): void
|
||||
|
Reference in New Issue
Block a user