1 Commits
2 changed files with 41 additions and 4 deletions

No files matched your search

+2 -2
View File
@@ -105,8 +105,8 @@ class BencodeTorrent extends Bencode
return strlen($element) === 0;
}
);
if (count($filter) > 0) {
throw new \RuntimeException('Cannot have empty path for a file');
if (count($filter) === count($file[$path_key]) && $file['length'] !== 0) {
throw new \RuntimeException('Cannot have a file with no path');
}
}
}
+39 -2
View File
@@ -465,7 +465,7 @@ class BencodeTorrentTest extends \PHPUnit\Framework\TestCase
$bencode->getEncode();
}
public function testInvalidPath(): void
public function testEmptyPathPart(): void
{
$data = [
'encoding' => 'UTF8',
@@ -473,7 +473,44 @@ class BencodeTorrentTest extends \PHPUnit\Framework\TestCase
'files' => [
0 => [
'length' => 1234,
'path' => ['']
'path' => [
'',
'01 - test test',
]
]
],
'name' => 'test',
'length' => 1213134,
'pieces' => 'fake pieces string'
]
];
$bencode = new BencodeTorrent();
$bencode->setData($data);
$this->assertSame(
[
'total_size' => 1234,
'files' => [
0 => [
'path' => '/01 - test test',
'size' => 1234,
],
],
],
$bencode->getFileList()
);
}
public function testEmptyPath(): void
{
$data = [
'encoding' => 'UTF8',
'info' => [
'files' => [
0 => [
'length' => 1234,
'path' => [
'',
]
]
],
'name' => 'test',