Skip to content

Commit

Permalink
SplFileInfo: Handle empty filename case
Browse files Browse the repository at this point in the history
  • Loading branch information
jnvsor committed Mar 8, 2023
1 parent b8b1da8 commit 1033fc4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Binary file modified build/kint.phar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/Zval/Representation/SplFileInfoRepresentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct(SplFileInfo $fileInfo)
$this->path = $fileInfo->getPathname();

try {
if ($fileInfo->getRealPath()) {
if (\strlen($this->path) && $fileInfo->getRealPath()) {
$this->perms = $fileInfo->getPerms();
$this->size = $fileInfo->getSize();
$this->owner = $fileInfo->getOwner();
Expand Down
42 changes: 42 additions & 0 deletions tests/Zval/Representation/SplFileInfoRepresentationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function testConstructFile()
$this->assertSame(__FILE__, $r->path);
$this->assertSame(__FILE__, $r->realpath);
$this->assertNull($r->linktarget);
$this->assertSame(\str_split('-rw-r--r--'), $r->flags);

if ('file' === \filetype(__FILE__)) {
$this->assertTrue($r->is_file);
Expand Down Expand Up @@ -120,6 +121,7 @@ public function testConstructFileLink()
$this->assertSame($f, $r->path);
$this->assertSame(__FILE__, $r->realpath);
$this->assertSame(__DIR__.'/testFileLink', $r->linktarget);
$this->assertSame(\str_split('lrw-r--r--'), $r->flags);

if ('link' === \filetype($f)) {
$this->assertTrue($r->is_file);
Expand Down Expand Up @@ -150,6 +152,7 @@ public function testConstructLinkedFile()
$this->assertSame($f, $r->path);
$this->assertSame(__FILE__, $r->realpath);
$this->assertNull($r->linktarget);
$this->assertSame(\str_split('-rw-r--r--'), $r->flags);

if ('file' === \filetype($f)) {
$this->assertTrue($r->is_file);
Expand Down Expand Up @@ -178,6 +181,7 @@ public function testConstructDir()
$this->assertSame(__DIR__, $r->path);
$this->assertSame(__DIR__, $r->realpath);
$this->assertNull($r->linktarget);
$this->assertSame(\str_split('drwxr-xr-x'), $r->flags);

if ('dir' === \filetype(__DIR__)) {
$this->assertFalse($r->is_file);
Expand Down Expand Up @@ -211,6 +215,7 @@ public function testConstructOpenBaseDir()
$this->assertFalse($r->is_file);
$this->assertFalse($r->is_dir);
$this->assertFalse($r->is_link);
$this->assertSame(\str_split('----------'), $r->flags);
}

/**
Expand All @@ -233,6 +238,7 @@ public function testConstructDirLink()
$this->assertSame($f, $r->path);
$this->assertSame(\dirname(__DIR__), $r->realpath);
$this->assertSame(__DIR__.'/testDirLink', $r->linktarget);
$this->assertSame(\str_split('lrwxr-xr-x'), $r->flags);

if ('link' === \filetype($f)) {
$this->assertFalse($r->is_file);
Expand Down Expand Up @@ -263,6 +269,7 @@ public function testConstructLinkedDir()
$this->assertSame($f, $r->path);
$this->assertSame(__DIR__, $r->realpath);
$this->assertNull($r->linktarget);
$this->assertSame(\str_split('drwxr-xr-x'), $r->flags);

if ('dir' === \filetype($f)) {
$this->assertFalse($r->is_file);
Expand Down Expand Up @@ -293,6 +300,7 @@ public function testConstructPipe()
$this->assertSame($f, $r->path);
$this->assertSame($f, $r->realpath);
$this->assertNull($r->linktarget);
$this->assertSame(\str_split('prwxr-xr-x'), $r->flags);

if ('fifo' === \filetype($f)) {
$this->assertFalse($r->is_file);
Expand Down Expand Up @@ -323,6 +331,7 @@ public function testConstructSocket()
$this->assertSame($f, $r->path);
$this->assertSame($f, $r->realpath);
$this->assertNull($r->linktarget);
$this->assertSame(\str_split('srwxr-xr-x'), $r->flags);

if ('socket' === \filetype($f)) {
$this->assertFalse($r->is_file);
Expand Down Expand Up @@ -353,6 +362,7 @@ public function testConstructCharacterDevice()
$this->assertSame($f, $r->path);
$this->assertSame($f, $r->realpath);
$this->assertNull($r->linktarget);
$this->assertSame(\str_split('crw-rw-rw-'), $r->flags);

if ('char' === \filetype($f)) {
$this->assertFalse($r->is_file);
Expand Down Expand Up @@ -409,6 +419,7 @@ public function testConstructBlockDevice()
$this->assertSame($f, $r->path);
$this->assertSame($f, $r->realpath);
$this->assertNull($r->linktarget);
$this->assertSame(\str_split('brw-rw----'), $r->flags);

if ('block' === $type) {
$this->assertFalse($r->is_file);
Expand Down Expand Up @@ -446,6 +457,37 @@ public function testConstructNone()
$this->assertFalse($r->is_file);
$this->assertFalse($r->is_dir);
$this->assertFalse($r->is_link);
$this->assertSame(\str_split('----------'), $r->flags);
}

/**
* @covers \Kint\Zval\Representation\SplFileInfoRepresentation::__construct
* @covers \Kint\Zval\Representation\SplFileInfoRepresentation::getSize
* @covers \Kint\Zval\Representation\SplFileInfoRepresentation::getMTime
*/
public function testConstructEmpty()
{
$f = '';

$r = new SplFileInfoRepresentation(new SplFileInfo($f));

$this->assertNull($r->size);
$this->assertNull($r->getSize());
$this->assertNull($r->ctime);
$this->assertNull($r->mtime);
$this->assertNull($r->getMTime());
$this->assertNull($r->perms);
$this->assertNull($r->owner);
$this->assertNull($r->group);
$this->assertSame('Unknown file', $r->typename);
$this->assertSame('-', $r->typeflag);
$this->assertSame($f, $r->path);
$this->assertNull($r->realpath);
$this->assertNull($r->linktarget);
$this->assertFalse($r->is_file);
$this->assertFalse($r->is_dir);
$this->assertFalse($r->is_link);
$this->assertSame(\str_split('----------'), $r->flags);
}

/**
Expand Down

0 comments on commit 1033fc4

Please sign in to comment.