mirror of
https://github.com/DirectoryLister/DirectoryLister.git
synced 2025-08-29 08:40:42 +02:00
Fixed incorrect file link URLs
This commit is contained in:
@@ -18,6 +18,10 @@ class Url extends ViewFunction
|
||||
{
|
||||
$path = preg_replace('/^[.\/]+/', '', $path);
|
||||
|
||||
if (is_file($path)) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
return empty($path) ? '' : sprintf('?dir=%s', ltrim($path, './'));
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ use Tests\TestCase;
|
||||
|
||||
class UrlTest extends TestCase
|
||||
{
|
||||
public function test_it_can_return_a_url(): void
|
||||
public function test_it_can_return_a_directory_url(): void
|
||||
{
|
||||
$url = new Url($this->container, $this->config);
|
||||
|
||||
@@ -16,7 +16,7 @@ class UrlTest extends TestCase
|
||||
$this->assertEquals('?dir=some/file.test', $url('some/file.test'));
|
||||
}
|
||||
|
||||
public function test_it_can_return_a_url_in_a_subdirectory(): void
|
||||
public function test_it_can_return_a_directory_url_in_a_subdirectory(): void
|
||||
{
|
||||
$_SERVER['SCRIPT_NAME'] = '/some/dir/index.php';
|
||||
|
||||
@@ -26,4 +26,13 @@ class UrlTest extends TestCase
|
||||
$this->assertEquals('?dir=some/path', $url('some/path'));
|
||||
$this->assertEquals('?dir=some/file.test', $url('some/file.test'));
|
||||
}
|
||||
|
||||
public function test_it_can_return_a_file_url(): void
|
||||
{
|
||||
chdir($this->filePath('.'));
|
||||
|
||||
$url = new Url($this->container, $this->config);
|
||||
$this->assertEquals('README.md', $url('README.md'));
|
||||
$this->assertEquals('subdir/alpha.scss', $url('subdir/alpha.scss'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user